jquery css with dynamically created element not working -


i'm creating element using jquery appending one. i'm trying style header doesn't seem working reason. there doesn't seem syntax errors. it's appending div , text appearing, it's not being styled.

 jquery('<h3/>', {  text: 'todays news', css: ('background-color', 'red'), id: 'tdn'  }).appendto('#div1'); 

any appreciated

try wrap css style inside { } instead of ( )

jquery('<h3/>', {     text: 'todays news',     id: 'tdn',     css: {'background-color': 'red'}, }).appendto('#div1'); 

fiddle demo

or can use .css() well:

jquery('<h3/>', {     text: 'todays news',     id: 'tdn' }).css('background-color', 'red').appendto('#div1'); 

fiddle demo


Comments

Popular posts from this blog

java - Intellij Synchronizing output directories .. -

git - Initial Commit: "fatal: could not create leading directories of ..." -