Reputation: 1553
How can I access the header tags in an accordion. i.e Sample 1, Sample 2 and Sample 3.
I have tried using following ways for accessing with no success.
$("#accordion div h3 a").text()
or
alert($("#accordion div h3").text())
gives only last accordion i.e.
alert($("#accordion div a").text())
gives output as clickhereclickhere...
HTML:
<div id="dia">
<div id="dialog" title="Detailed FeedBack ">
<div id="accordion">
<h3><a href="#">sample 1</a></h3>
<h3><a href="#">sample 2</a></h3>
<h3><a href="#">sample 3</a></h3>
</div>
</div>
</div>
Upvotes: 0
Views: 189
Reputation: 33661
your #accordion
is your div so all you need is this
$("#accordion h3 a") // <-- gets all a tags under #accordion --> h3
or you can just use
$("#accordion a") // <-- gets all a tags under #accordion
depending on what your structure/requirements are
or even more specific
$("#accordion > h3 > a")
It will return an array of jquery objects which you can retrieve either using
[index]
// <-- dom element - allows use of native dom methods
ex. $("#accordion > h3 > a")[0]
// <-- gets first element
or
.eq(index)
// <-- jquery object which allows use of jQuery methods + chaining
ex. $("#accordion > h3 > a").eq(0)
//<-- gets first element
Upvotes: 2
Reputation: 207901
Use:
$("#accordion a").eq(0).text()
to access the text content of the first tab's link. Increment 0 for the others.
Upvotes: 1