How would I access the div with a text node of 2?
<script>
$(document).ready(function() {
alert($('.content').length);
$('.content').click(function(e) {
// ...
})
});
</script>
<div class='content'>1</div>
<div class='content'>2</div>
<div class='content'>3</div>
<div class='content'>4</div>
Depends on whether that’s your only HTML or not. If your items only contain single digits,
containswill work. If not, you’ll need to filter based on the content.On the other hand if you just want the second element, regardless of content, you can use
eq().