Reputation: 1961
I am looking for JQuery script to change a tag class inside of specific tags.
For example,
<h4 class=" id_1">
<span class="favorite"> </span>
</h4>
In above tags, I want to change class="favorite"
to class="title"
by id_1 class.
CSS for favorite and title is different.
Thank you!
Upvotes: 0
Views: 1506
Reputation: 67
$('.id_1 .favorite').removeClass('favourite').addClass('title');
Upvotes: 0
Reputation: 337560
You can use addClass
and removeClass
to achieve this:
$('.id_1 .favorite').removeClass('favorite').addClass('title');
You could also use toggleClass
if you can guarantee the starting state of the relevant elements:
$('.id_1 .favorite').toggleClass('favorite title');
Upvotes: 0
Reputation: 85545
You can also use attr method:
$('.id_1 .favorite').attr('class','title');
Using JavaScript:
document.querySelector('.id_1 .favorite').setAttribute('class','title');
Upvotes: 1
Reputation:
You can use addClass and removeClass:
$(".id_1").removeClass("favourite").addClass("title");
Upvotes: 1