Enjoy an ad free experience by logging in. Not a member yet? Register.
|
|
Results 1 to 2 of 2
-
03-10-2016, 02:30 PM #1New to the CF scene
- Join Date
- Mar 2016
- Posts
- 7
- Thanks
- 5
- Thanked 0 Times in 0 Posts
do not understand what .each() does here
Hi guys,
I was reading about jquery .each() function and I saw something I do not understand. I was wondering if someone could explain it to me
It is a text field with the id person for example
I thought .each() was used to iterate over many elements. Is it also possible to use it on a single element? I do not understand what the person is doing here. Is it because the value of the field is dynamic?Code:$('#person').each(function(){ var value = $(this).val() })
Thanks in advance for the helpful answers
-
03-11-2016, 04:49 AM #2
your assumptions are correct - this is a very silly piece of code. In legal HTML, an ID must be unique to each element, and iterating over a collection of one is as pointless as it sounds. You would get exactly the same result from this one-liner:
Code:var value = $('#person').val();
-
Users who have thanked xelawho for this post:
princesse (03-17-2016)



Reply With Quote
