Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jquery removing html element from variable

Tags:

html

jquery

dom

I have html saved in a variable

var  itinerary =  $('.events_today').html() ;

I have lots of html and one button I want to remove. It has the id "myButton". How can I remove it from the html saved in my variable

like image 827
LeBlaireau Avatar asked Dec 21 '22 10:12

LeBlaireau


2 Answers

I suggest this approach

var itinerary = $('.events_today')
                .clone(true)       /* get a clone of the element and from it */
                .find('#myButton') /* retrieve the button, then */
                .remove()          /* remove it, */
                .end()             /* return to the previous selection and */
                .html() ;          /* get the html */
like image 90
Fabrizio Calderan Avatar answered Dec 28 '22 22:12

Fabrizio Calderan


Try this:

itinerary.filter(function() { return $(this).not("#myButton"); });
like image 32
Zachary Kniebel Avatar answered Dec 28 '22 23:12

Zachary Kniebel