I know that the jQuery selector returns an object of matching DOM elements, e.g.
typeof $('p'); // returns "object"
But when I try to access all elements in the object, it seems the only effect the first, e.g.
$('p').html('test'); // only sets the first <p></p> to test
I know I can do
$('p').each(function() { $(this).html('test') });
But is this the preferred method? Is there some other way to set mass attributes?
EDIT: Sorry guys, I was trying to access the wrong tag 🙁 and it was unrelated to any jQuery issue. But everything said below is useful and might be helpful to someone so I won’t close the question.
If you want to apply to all the
p, then there is no need to loop. You can just apply by:jsFiddle