Q:

Get two attributes using Jquery

i've a problem using Jquery.
This is my html markup:
 <li><a class="" value="short" tool="car" type="monov"> text </a></li>

I have to capture, after selecting an LI, "ttol" and "type" attr.
This is my code:
var selectedTool = $(this).attr('tool');
var selectedType = $(this).attr('type');

But it doesn't work, it arrives undefined...But if i use this:
$(this).html();

i get:
<li><a class="" value="short" tool="car" type="monov"> text </a></li>

How can i get these attributes?
Thanks

A:

try below code :
    var $anchor = $(this).find("a");
    var selectedTool = $anchor.attr('tool');
    var selectedType = $anchor.attr('type');

you were trying to access the attributes of li and the attributes 'tool' and 'type' are on anchor so it was coming undefined.

