How to toggle prepend in jquery -
i want toggle css link using jquery, via single button.
catch is, want in target of iframe.
so far have following code, insets link fine:
$("#custom").click(function() { $("#content").contents().find("head").prepend("<link href=\"../build/css/custom.css\" rel=\"stylesheet\" id=\"custom-css\">"); });
this activated following html:
<div class="toggle-custom"> <a target="custom" id="custom" class="btn btn-primary btn-lg">toggle custom style</a> </div> <iframe id="content" src="carousel.html" frameborder="0" scrolling="auto"> </iframe>
i know way remove is:
$("#content").contents().find("#custom-css").remove();
but how can toggle same button?
thanks
try
var contents = $("#content").contents(); var ccss = contents.find("head").find("#custom-css"); if(ccss.length){ ccss.remove() } else { contents.find("head").prepend("<link href=\"../build/css/custom.css\" rel=\"stylesheet\" id=\"custom-css\">"); }
Comments
Post a Comment