javascript - Changing element background color with jQuery .append -


so javascript code creating list of table items, want able change color of row according selections made, each time new item added. here's code

   if ( valid ) {         $( "#tasks2 tbody" ).append( "<div id='tasklist'><ul class='taskscreen2'><tr>" +           "<td><h1>"  + type.val() + "</h1></td>"+"<td class='title'><h3>"+  title.val() + " </td>"  +"<td>"+ wordcount.val() + "</h3></td>"  +"<td><p>"+  description.val() + "</p></td>"  + "<td>"+ deadline.val() + "</td>"+         "</tr></ul></div>"                 + "<script> if ($('#type').val()=='dissertation')"         + "{document.getelementbyid('tasklist').style.backgroundcolor = 'red';} </script>"    ); 

this changes color of top item while new ones remains same. want change bg colour of new item whenever added. tried including function both inside , outside .append did not work. appreciated.

you appending divs same id's(which wrong).use class instead , should work.


Comments

Popular posts from this blog

facebook - android ACTION_SEND to share with specific application only -

python - Creating a new virtualenv gives a permissions error -

javascript - cocos2d-js draw circle not instantly -