applying css through jquery for a dynamically created divs -
i trying add css properties using jquery dynamically created divs , specify jquery css part @ document load time. when add divs dynamically later using event, divs class names not properties specified. ive added sample code in fiddle.. http://jsfiddle.net/negzy/9/
in fiddle, div gets appended on button click, bt u can see doesnt properties specified..
var eventsarray=["test1", "test2"]; $(".testclick").on("click",function(){ var printhtml=''; for(var i=0; i<eventsarray.length; i++){ printhtml = "<div class='eventnametagcolor"+eventsarray[i] +"'> test </div>" } $(".appendingdiv").append(printhtml); }); $(document).ready( function() { for(var i=0; i<eventsarray.length; i++){ $(".eventnametagcolor"+ eventsarray[i]).css({"background" : "linear-gradient(center top , #f68a28, #f36c00) repeat scroll 0 0 transparent" , "width": "250px", "font-weight" : "bold", "height" : "30px", "color":"#ffffff", "float":"left" }); } });
the issue code, here: http://jsfiddle.net/negzy/10/
you can see i've added:
<div class="eventnametagcolortest1"></div> you can see if put element you're changing css of on page originally, css applies fine. problem element not exist @ time you're wanting change css of (on document load) - needs done on click event, looks of things.
Comments
Post a Comment