javascript - Changing color of each row with jQuery dialog .append -
i building application allow adding tasks list , changing colour of them according selections made.
i using build list of items, how achieve http://s4.postimg.org/npplicbnh/2222.png
here .append code @narawa games helped me with. @ moment whenever new item added changes color of every other item added before same color. want able have different items in different colors.
if ( valid ) { $( "#tasks2 tbody" ).append("\<div class='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>var typesup=$('#type').val();var tasks=$('.tasklist');if(typesup=='dissertation'){tasks.css('border-color', 'red');}else if (typesup=='report'){tasks.css('border-color', 'blue');}\ ");
here's jsfiddle example - https://jsfiddle.net/ynwlykpk/
all welcome. cheers
assuming want style table row added, , leave others untouched, try :
if ( valid ) { var $task = $("<tr class='tasklist'>" + "<td><h1>" + type.val() + "</h1></td>" + "<td class='title'><h3>" + title.val() + "</h3></td>" + "<td>" + wordcount.val() + "</td>" + "<td><p>" + description.val() + "</p></td>" + "<td>" + deadline.val() + "</td>" + "</tr>" ).appendto("#tasks2 tbody"); switch($('#type').val()) { case 'dissertation': $task.css('border-color', 'red'); break; case 'report': $task.css('border-color', 'blue'); break; default: $task.css('border-color', 'green'); } }
tidied because appending <div><ul><tr>...</tr></ul></div>
tbody
element nonsense.
edit in response @tushars comments
alternatively, write css directives default , each task type :
.tasklist { border-color: green; } .tasklist.dissertation { border-color: red; } .tasklist.report { border-color: blue; }
then style rows applying appropriate class row :
if ( valid ) { var type = type.val(); $("<tr class='tasklist'>" + "<td><h1>" + type.val() + "</h1></td>" + "<td class='title'><h3>" + title.val() + "</h3></td>" + "<td>" + wordcount.val() + "</td>" + "<td><p>" + description.val() + "</p></td>" + "<td>" + deadline.val() + "</td>" + "</tr>" ).addclass(type).appendto("#tasks2 tbody"); }
Comments
Post a Comment