Wakie
asked on
Import CSS from one ID to another ID using jQuery
Hi all,
I'm wanting to import an existing ID's style ("box") into a different ID's style ("box2"), however my code below does not work as expected.
Does anyone know if this is possible or can direct me to an appropriate jQuery plugin?
Thanks,
Wakie.
I'm wanting to import an existing ID's style ("box") into a different ID's style ("box2"), however my code below does not work as expected.
Does anyone know if this is possible or can direct me to an appropriate jQuery plugin?
Thanks,
Wakie.
<style type="text/css">
#box { width: 250px; height: 200px; }
</style>
<script type="text/javascript">
$(function() {
$('box2').css('#box');
});
</script>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
because you have to wait until the elements have been created by the DOM. That's why most jQuery code is wrapped in document ready code - it ensures that all the elements you are about to reference exist and that there properties are set.
Try
$(document).ready(function () {
$("#title").addClass("ui-w idget-head er ui-corner-all");
$("#box").addClass("thebox ui-widget-content ui-corner-all");
});
Try
$(document).ready(function
$("#title").addClass("ui-w
$("#box").addClass("thebox
});
ASKER
Great stuff, appreciate the help :)
Always a pleasure, best of luck with rest of the job
ASKER
I ended up using the solution below.
However, any idea why I have to put it at the bottom of the code and not in with the rest of my JavaScript?
Open in new window