.html()
function on class selector ($('.class').html()
) applies only to the first element that matches it. I'd like to get a value of all elements with class .class
.
each(), which is used to iterate, exclusively, over a jQuery object. The $. each() function can be used to iterate over any collection, whether it is an object or an array. In the case of an array, the callback is passed an array index and a corresponding array value each time.
To get HTML content of an element using jQuery, use the html() method. The html() method gets the html contents of the first matched element.
With jQuery, you can use the . append() method to insert the specified HTML as the last child of the div container.
val() method is primarily used to get the values of form elements such as input , select and textarea . When called on an empty collection, it returns undefined .
You are selection all elements with class .class
but to gather all html content you need to walk trough all of them:
var fullHtml; $('.class').each(function() { fullHtml += $(this).html(); });
search items by containig text inside of it:
$('.class:contains("My Something to search")').each(function() { // do somethign with that });
Code: http://jsfiddle.net/CC2rL/1/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With