I'm trying to setup some hyperlinks to set inline styles for various elements on a webpage. So far I have been able to store the element and attribute settings in hidden span elements and pass them to an alert dialog. However when I try to set these styles using the css function it is not working or throwing any errors.
HTML:
<a class="styleswitch">Boxed
<span class="elementselector" style="display:none">#page</span>
<span class="styleattributes" style="display:none">"width": "1000px"</span>
</a>
<a class="styleswitch">Wide
<span class="elementselector" style="display:none">#page</span>
<span class="styleattributes" style="display:none">"width": "100%"</span>
</a>
jQuery:
jQuery(document).ready(function(){
jQuery('a.styleswitch').click(function(){
var element_selector = jQuery(this).find("span.elementselector").contents().text(),
style_attributes = jQuery(this).find("span.styleattributes").contents().text();
// alert('Set ' + element_selector + ' to ' + style_attributes + '');
jQuery(element_selector).css( style_attributes );
return false;
});
.css()method, this means you are using it as a getter and not a setter.