In my HTML I have a div
:
<div id="devicelayout">
Some text here
</div>
and corresponding CSS:
#devicelayout
{
width:1078px;
}
Once my page is loaded, how do I change the rules of CSS #devicelayout
?
In my HTML I have a div
:
<div id="devicelayout">
Some text here
</div>
and corresponding CSS:
#devicelayout
{
width:1078px;
}
Once my page is loaded, how do I change the rules of CSS #devicelayout
?
If you just want to change css styles of the element you can directly assign a different class to it or change css properties of the element using JQuery using
$("#devicelayout").css("property", "value")
or
$("#devicelayout").addClass("newClass")
Or if you want to change css rules then try modifying stylesheet rules at document.styleSheets
object. See here
$(document).ready(function(){
$('#devicelayout').css("attributeName","attributeValue");
})
Here you have some more info about using css function: http://api.jquery.com/css/
Try this code:
$(document).ready(function(){
$("#devicelayout").css("width","500px");
});
you can use jquery as a solution for this... put all the css changes you want your #devicelayout to happen after page load into a css file for example devicelayout.css. then in your script tag (ofcourse after you include the jquery library) add this code...
$(document).ready(function(){
if($("#devicelayout").size()>0){ /*Check if the id "#devicelayout" exists within your DOM*/
$("head").append($("<link rel='stylesheet' href='devicelayout.css' type='text/css' />")); /*if true, the new <link> element is appended to the <head> element */ }
});
This will also let you change the css of a number of ids after page load, not just one. hopefully this helps