Friday, 23 August 2013

How to toggle prepend in jquery

How to toggle prepend in jquery

I want to toggle a css link using a jquery, via a single button.
Catch is, I want to do it in the target of an iframe.
So far I have the following code, which insets the link fine:
$("#custom").click(function() {
$("#content").contents().find("head").prepend("<link
href=\"../build/css/custom.css\" rel=\"stylesheet\"
id=\"custom-css\">");
});
This is activated by the 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 that the way to remove it is:
$("#content").contents().find("#custom-css").remove();
But how can I toggle it from the same button?
Thanks

No comments:

Post a Comment