I am creating a popupwindow and I want to add a css file to that popupwindow. Below is the code for popupwindow. I have a JavaScript which creates a popupwindow.
<a href="popupwindowcontent.xhtml" title="Print" class="popupwindow">Print1</a>
Now I want to add a css file to this popupwindow. I tried something like
$('.popupwindow').append('<link rel="stylesheet" href="css/style2.css" type="text/css" />'); $('head').append('<link rel="stylesheet" href="css/style2.css" type="text/css" />');
but it doesn't work.
jQuery has several methods for CSS manipulation. We will look at the following methods: addClass() - Adds one or more classes to the selected elements. removeClass() - Removes one or more classes from the selected elements.
jQuery css() Method The css() method sets or returns one or more style properties for the selected elements. When used to return properties: This method returns the specified CSS property value of the FIRST matched element.
The @import rule allows you to import a style sheet into another style sheet. The @import rule must be at the top of the document (but after any @charset declaration). The @import rule also supports media queries, so you can allow the import to be media-dependent.
Apply multiple CSS properties using a single JQuery method CSS( {key1:val1, key2:val2....). You can apply as many properties as you like in a single call. Here you can pass key as property and val as its value as described above.
$('head').append('<link rel="stylesheet" href="style2.css" type="text/css" />');
This should work.
This is how I add css using jQuery ajax. Hope it helps someone..
$.ajax({ url:"site/test/style.css", success:function(data){ $("<style></style>").appendTo("head").html(data); } })
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With