javascript - Using jQuery to modify the name of a CSS class - Not working on load -
i have following code (using xslt/html)
<div class="{@classname} modify""><img src="{substring-before(@image, ', ')}"/></div>
the "classname" being through dynamically through cms, when there 2 options selected, segregated bunch of other characters. result end similar this:
;#class1;#class2;#
what i'm trying modify class names based on set to. written following code, when entered browsers console window, works absolute charm. however, when added actual page, doesn't take effect. i'm wondering if it's priority thing or else:
$('.modify').each(function(){ var newprimeitem= "primary item"; var newitem = "item"; if ( $(this).attr('class') == ";#primary;#item;# modify") { $(this).attr('class', newprimeitem);} if ( $(this).attr('class') == ";#item;# modify") { $(this).attr('class', newitem );} });
any on appreciated.
thanks in advance :)
in order trigger function on page load, need wrap in dom ready.
here tutorial on dom ready jquery.
$(document).ready(function() { // code executed on page load. });
Comments
Post a Comment