Reputation: 89
How to target an HTML element based on its title tag?
let's say we have:
<a class="cat" title="categoryName">categoryName</a>
How to target this anchor element using its title tag then append some text to it.
I tried this but it doesn't work:
$(".cat['title' = *categoryName*]").append('*someText*');
also tried this but it doesn't work:
$(".cat['title' ~= *categoryName*]").append('*someText*');
Upvotes: 1
Views: 377
Reputation: 3011
21 problems:
a
tag - you've prematurely closed it, and This works:
$(".cat[title = 'categoryName']").append('someText');
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<a class="cat" title="categoryName">categoryName</a>
Upvotes: 2