0

I have the specific code :

<script>

$.fn.revert = function(){
return this.each(function() {
var txt = $(this).html().replace(/<span class="gradientizer-done" style='color:rgb\(\d{1,3},\d{1,3},\d{1,3}\)>.<\/span>/g,'');
$(this).html(txt);
});
};

</script>

And this code :

<p class="grad2" one="ffffff" second="000000">
<span class="gradientizer-done" style="color:rgb(255,255,255)"> </span>
<span class="gradientizer-done" style="color:rgb(219,219,219)">H</span>
<br>
<span class="gradientizer-done" style="color:rgb(109,109,109)">l</span>
</p>

Basically, the revert function intended to change all the gradientizer-done class to text , that is I expect the follow result when running revert on $(".grad2").revert():

<p class="grad2" one="ffffff" second="000000">
 H<br>l</p>

But i see no change in <p></p>

2 Answers 2

2

You have put a single quote after style= attribute instead of double quotes and also you forget to put double quotes at the end of style attribute.

$(this).html().replace(/<span class="gradientizer-done" style="color:rgb\(\d{1,3},\d{1,3},\d{1,3}\)">.<\/span>/g,'');
                                                              ^                                    ^
Sign up to request clarification or add additional context in comments.

3 Comments

Thank you very much. Just noted that I also forgot the capture group and $1
capturing group? where? your regex doesn't have any capturing group.
Am saying i forgot to add that to make my function work properly.. Nvm
2

Better solution would be:

var $container = $(".grad2");
$container.find(".gradientizer-done").each(function(){
  $(this).after($(this).text())
  $(this).remove()
})

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.