How tochange the text inside a link with jQuery -


i want change text inside link jquery when href attribute undefined. here code;

<input type="text" id="sample"/><button id="button">submit</button> <table id="table" border="1"> <tr>     <td>less 50</td>      <td>less 100</td>      <td>less 500</td>      <td>less 1000</td>      <td>more 1000</td> </tr>  </table> 

js:

$("#button").click(function()    {      var val=$("#sample").val();//alert(val)        if(val<50){            var col1=val;          }else if(val<100){            var col2=val;          }else if(val<500){            var col3=val;          }else if(val<1000){            var col4=val;          }else if(val>1000){            var col5=val;          }           var row='<tr>'+                   '<td><a href="#">'+col1+'</a></td>'+                   '<td><a href="#">'+col2+'</a></td>'+                   '<td><a href="#">'+col3+'</a></td>'+                   '<td><a href="#">'+col4+'</a></td>'+                   '<td><a href="#">'+col5+'</a></td>'                    $("#table tr:last").after(row);                    $("#table").each(function(){                       if ($(this).attr('href') == undefined){                          var href=$(this).attr('href');                                                                    $(href).text("");                        }                     });         }       ); 

i need undefined href text() null or 0.i used this.,

   $("#table").each(function(){         if($(this).attr('href') == undefined){             var href=$(this).attr('href');              $(href).text("");           }      }); 

but doesn't worked. sql fiddle:http://jsfiddle.net/2ok5mzx9/

define them 0.

var col1 = 0; col2 = 0; col3 = 0; col4 = 0; col5 = 0;  if (val < 50) {     col1 = val; } else if (val < 100) {     col2 = val; } else if (val < 500) {     col3 = val; } else if (val < 1000) {     col4 = val; } else if (val > 1000) {     col5 = val; } 

working demo


Comments

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -