Tutorial :attribute value



Question:

I have an atribute test that I get the value of like this

$('#row').attr("test");  

now I need to put this in a loop and get the value but its not working. This is what I am doing

for(var i=0; i=mySpansCount; i++)    {     var x=($('#row').attr("test"));     alert(x[i]);      }  

All I am getting in alert box is undefined.
Thanks


Solution:1

I'm guessing that maybe you need to use .each() like this:

<div id="row">      <span test="start">Hi </span>there, <span test="middle">I</span> am testing this <span test="end">out</span>.      <div><span test="nested">Bye!</span></div>  </div>    <script type="text/javascript">  jQuery(function($) {      $('span', '#row').each(function() {          alert($(this).attr('test'));      });  });  </script>  

Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Previous
Next Post »