Let’s say I have
<div id="1">
<span id="name">Josh</span>
<div id="quote">Run</div>
</div>
<div id="2">
<span id="name">Mark</span>
<div id="quote">Run</div>
</div>
How would I select the name between the span tags from the first div?
$("#quote").click(function(){
var name = $('#name').html();
});
Firstly,
id‘s have to be unique in an html document. So,ideally, you need to change those id’s within the div to aclass. Secondly,id‘s cannot begin with a numeric, so you need to change your div id’s to start with a letter or underscore.With that in mind, given this structure:
you would be looking for: