This should be simple, but I can't figure it out
For example, lets assume the class .contentdiv is what were searching for.
I want to obtain (or select) the second or (x amount) .contentdiv in a document then get the html of that div.
x being the div i want to select so pretend x is 1,2 or 3 or any number
jQuery('#slider').filter('.contentdiv').match(x).html();
There are a couple of ways, but:
$('#slider').filter('contentdiv').eq(x).html();
also
$('#slider').filter('.contentdiv:eq(' + x + ')').html();
but that's messier (in my opinion).
edit — thanks @patrick: the initial selector is selecting a single element (of necessity, because "id" values have to be unique). Perhaps you meant $('#slider div.contentdiv')
which would get all the <div>
elements under` the "slider" container.
And another good comment further clarifies that the indexing of .eq()
and the ":eq()" selector thingy is zero-based.
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