javascript - Function to append an array of classes, then split those classes in jQuery? -
i have table generated:
<table> <tr> <td><input /></td> <td><span>30</span></td> <td><input /><td> </tr> </table>
this basic structure. there many <tr>
elements virtually same. each tr, need append class a1, b1, c1
on elements. after function should like:
<table> <tr> <td><input class="a1" /></td> <td><span class="a2">30</span></td> <td><input class="a3" /><td> </tr> <tr> <td><input class="b1" /></td> <td><span class="b2">30</span></td> <td><input class="b3" /><td> </tr> </table>
and on until last group this, each 1 letter increase on last group.
after i'm going need calculations have split these classes. like:
$("input").keyup(function(){ var originalval = $(this).attr("class"); //here need split class letter (a) or (b) etc //then perform calculations $(orignalval + "1") * $(originalval = "2") etc
i figure easiest way want do, calculate a1 input times a2 span , insert result in a3 input , on groups. i'm open other suggestions well.
something following should work:
var chars = "abcdefghijklmnopqrstuvwxyz".split(''); $('table tr').each(function(i) { $('td', this).children().addclass(function(j) { return chars[i] + ++j; }); });
Comments
Post a Comment