javascript - applying jquery code to more than one class -
i have little snippet of code applied 1 class
function replacesf(foo,bar) { j$('.labelcol').children().each(function(){ console.log('i on children each labelcol'); console.log('foo: '+foo); console.log('bar: '+bar); console.log('jsthis.text: '+j$(this).text()); if(j$(this).text() == foo) { j$(this).html(''+bar); } else if(j$(this).text().trim().replace('\*','').replace('\n','') == foo) { j$(this).html(j$(this).html().replace(foo,''+bar)); } }); j$('.labelcol').each(function(){ if(j$(this).text() == foo ) { j$(this).html(''+bar); } }); }
but need use code 10 classes. what's best approach this? trying rewrite function replacesf(classname,foo,bar)
didn't results.
thanks.
you can modify selector like:
j$('.labelcol, .labelcol2, .labelcol3, .labelcol4, .labelcoln').children().each(function(){
...
Comments
Post a Comment