Skip to main content

How to count elements and take attribut of first?



I want to count all img elements and take attribute (alt) of FIRST of it. My try:







$('img').each(function(index) {

/* need count and take forst */

if(index=0){

var objid = $(this).attr('alt');

}

});







Can you help me with this?


Comments

  1. var $images = $('img');
    var imgCount = $images.length;
    var altAttrOfFirst = $images.first().attr('alt');

    ReplyDelete
  2. var $img= $('img');
    var count = $img.length;
    var attr = $img.first().attr('alt');

    ReplyDelete

Post a Comment

Popular posts from this blog

Slow Android emulator

I have a 2.67 GHz Celeron processor, 1.21 GB of RAM on a x86 Windows XP Professional machine. My understanding is that the Android emulator should start fairly quickly on such a machine, but for me it does not. I have followed all instructions in setting up the IDE, SDKs, JDKs and such and have had some success in staring the emulator quickly but is very particulary. How can I, if possible, fix this problem?