javascript - regain html after emptying it using jquery? -
i have if/else loop inside jquery. need hide html on text box inside if portion , regain @ else part. how can using jquery?
if (test == 1) { $(#id).html(""); //code hide html } else { //code regain }
code hide html works fine,but how regain code after emptying it?
you can't regain lost html unless have saved somewhere,
you can either show/hide element
if(test==1){ $(#id).hide(); } else{ $(#id).show(); }
or can store values somewhere in variable
var html = ""; if (test == 1) { html = $(#id).html(); $(#id).html( "" ); } else { $(#id).html( html ); }
or set localstorage (if browser supports it)
if (test == 1) { localstorage.setitem("savedhtml", $(#id).html()) ; $(#id).html( "" ); } else { $(#id).html( localstorage.getitem( "savedhtml" ) ); }
Comments
Post a Comment