Reputation: 4987
I have an icon element inside a link, how can I get its css class with jQuery (eg. icon
).
<a class="myclass"><i class="icon"></i>text</a>
I can get the text
var txt = $('.myclass').text();
but unable to get the class of the i.
Upvotes: 1
Views: 38
Reputation: 11693
working FIDDLE Way1
Now FIDDLE Way2
Use folowing
var txt = $('.myclass > i').prop('class');
alert(txt);
Means inside class myclass
find i , and then find its class property, You can also use attr.
OR
var txt = $('.myclass').find('i').prop('class');
alert(txt);
Upvotes: 2