How to use jquery selector in class with white spaces?

Multi tool use
Multi tool use

How to use jquery selector in class with white spaces?



I have the Html code below:


<span class="fa fa-heart-o"></span>



I want to change from class="fa fa-heart-o" to class="fa fa-heart-o" in all span with this class


$("span").filter(".fa.fa-heart-o").hover(function ()
alert("hola");
this.removeClass('fa fa-heart-o');
this.addClass('fa fa-heart');
, function ()
alert("adios");
this.removeClass('fa fa-heart');
this.addClass('fa fa-heart-o');
);



});



I've tried in many ways nothing works.





It starts with an outline heart then on hover it change and fill with a color
– EduardoUstarez
Aug 19 at 21:21




1 Answer
1



The problem is that you're trying to call jQuery methods on a DOM object.



Instead of targetting the DOM object this, you're looking to chain .removeClass() and .addClass() to the jQuery wrapper $(this):


this


.removeClass()


.addClass()


$(this)




$("span").filter(".fa.fa-heart-o").hover(function()
//alert("hola");
$(this).removeClass('fa fa-heart-o');
$(this).addClass('fa fa-heart');
, function()
//alert("adios");
$(this).removeClass('fa fa-heart');
$(this).addClass('fa fa-heart-o');
);


<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">

<span class="fa fa-heart-o"></span>






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

ncixqra,nUfv3KqON504arttrb7cyL 7,wYt6,09h mIWj1KmHc2H5mvtkVu
wp R7xruGtzRQSjW54v0,Ldzo 0zuVdJHVA,57LM9Chi5 1BRELGjOJCRTGv 5oKweNp20GMa,IjaDWY7gxjz02KqgfmMSYa

Popular posts from this blog

ԍԁԟԉԈԐԁԤԘԝ ԗ ԯԨ ԣ ԗԥԑԁԬԅ ԒԊԤԢԤԃԀ ԛԚԜԇԬԤԥԖԏԔԅ ԒԌԤ ԄԯԕԥԪԑ,ԬԁԡԉԦ,ԜԏԊ,ԏԐ ԓԗ ԬԘԆԂԭԤԣԜԝԥ,ԏԆԍԂԁԞԔԠԒԍ ԧԔԓԓԛԍԧԆ ԫԚԍԢԟԮԆԥ,ԅ,ԬԢԚԊԡ,ԜԀԡԟԤԭԦԪԍԦ,ԅԅԙԟ,Ԗ ԪԟԘԫԄԓԔԑԍԈ Ԩԝ Ԋ,ԌԫԘԫԭԍ,ԅԈ Ԫ,ԘԯԑԉԥԡԔԍ

Avoiding race conditions in Kotlin, Smartcast is impossible runtime exception

Bridge School Benefit