1

I'm trying to replace the content in an element, but nothing is happening. Not even getting an error back.

var total = 15;
$('.totals div h3 span').replaceWith("<p class='totaal'>" + total +" TOTAAL</p>");

Codepen: http://codepen.io/MennoK/pen/QpjNPZ

4
  • 2
    there is definitely an error in your code Uncaught TypeError: selectors.size is not a function Commented Feb 28, 2017 at 15:48
  • make sure $('.totals div h3 span') actually returns elements. When I tried it in your codepen I didn't see anything, which would explain why nothing is happening and you're not getting errors. Commented Feb 28, 2017 at 15:50
  • When you decide to publish some code on SO, try to avoid codepen. It's very slow and highly unreadable. There's a feature called 'code snippet' on SO. Use it instead. Commented Feb 28, 2017 at 15:50
  • in your codepen total is misspelled - totaal - is it the issue? Commented Feb 28, 2017 at 15:53

2 Answers 2

3

You need to replace the function .replaceWith() by .html()

e.g.

$('.totals div h3 span').html("<p class='totaal'>" + total +" TOTAAL</p>");

http://codepen.io/anon/pen/zZvEjV

Sign up to request clarification or add additional context in comments.

Comments

0
$('.totals div.wpb_wrapper h3 span').replaceWith("<span style='color: #ffffff;' class='tobtaal'>222 TOTAAL</span>");

try it! the text is not seen because is black, also there are two divs

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.