Here is some code:
http://jsfiddle.net/T65E3/3/
I want to get an attr when i know class
$("#find").click(function() {
$("#test").append($("#file").find("a.higlight").attr("rel"));
});
and html
<div id="file">
<ul>
<li>
<a class="higlight" rel="a">value_my</a>
<a class="sth" rel="b">val</a>
<a class="sth" rel="c">val2</a>
<a class="sth" rel="d">val3</a>
</li>
</ul>
</div>
<button type="submit" id="find">find</button>
<div id="test"></div>
Your code as-is (if you include jQuery, your example had MooTools), works fine. There’s just one thing I’d like to point out.
This will only return you the
relattribute of the first matched element. To get all therelattributes (if there were multiple elements), you can use.map.