freshtoUI
freshtoUI

Reputation: 321

how to remove an element from .html() string?

I am trying to remove few elements from .html() and get a fresh set of elements.I am trying .remove() to delete the elements, but, its not helping me. Can you please help me in this regard ?

Adding the code below with the fiddle link.

https://fiddle.jshell.net/g7kptrac/

Upvotes: 0

Views: 49

Answers (3)

Jobelle
Jobelle

Reputation: 2834

    $("#wrapper").find(".hide").each(function(){
    $(this).remove();
});

Upvotes: 0

vlence
vlence

Reputation: 495

Using jquery, you could do this:

$('cssSelector').remove();

Upvotes: 0

Umesh Sehta
Umesh Sehta

Reputation: 10659

this is because $(dom).find(".hide")doesn't exists anymore as $("#wrapper").html() return all child element it will return 0 elements. you can try this:-

var dom = $("#wrapper").html();
 $("#newList").html(dom);
 $("#newList").find(".hide").each(function(){
 $(this).remove();
});

or simple:-

$("#newList").find(".hide").remove()

Demo

Upvotes: 2

Related Questions