replaceWith() does not work like expected
Hi there,
This thing is driving me nuts. Tried all kinds of things to replace all img tags within a html string.
So I have this html on my page:
- <section><div class="content">Here is the html that has to be checked for IMG</div><div class="replyinfo"><span>25 Jan 2015, 13:18</span><a href="#" class="reply">Reply</a></div></section>
- <section><div class="content">Here is the html that has to be checked for IMG</div><div class="replyinfo"><span>26 Jan 2015, 15:02</span><a href="#" class="reply">Reply</a></div></section>
- <section><div class="content">Here is the html that has to be checked for IMG</div><div class="replyinfo"><span>27 Jan 2015, 08:43</span><a href="#" class="reply">Reply</a></div></section>
Then I have this jQuery:
- $(".reply").click(function(e) {
- e.preventDefault();
- var cmt = $(this).parents().find(".content").html();
- }
This will get the content of the content div (Don't know why closest() doesnt work but ok).
Now I want all image tags to be replaced inside the cmt string (Not on the page but only to process its output)...
I tried:
- var cmt2 = $('cmt').find("img").replaceWith("test");
and
- var cmt2 = $('cmt img').replaceWith("test");
But it all doesnt work and gives null or undefined when I print out the cmt2 output... :(
Can someone help me with this one?