jquery - Getting alt text from image in loop -


i've got bit of code searches instagram , returns number of results. these displayed in small grid in div 'imgdiv'. image title added 'alt' text each image , if put in alert('' + title + '); after 'prepend' function, can see titles accurately parsed in full.

the next part of code lets user click on image , see enlarged. part works fine , correct image enlarged , grid hidden. want add 'alt text' label beneath enlarged image - , goes wrong. though using parallel function 1 used retrieve img src, when run code below, enlarged image displayed, additional div created, first word of alt text shows - string breaks @ first white space.

can see i've gone wrong here:

$('#imgdiv').prepend('<img alt=' + title + ' width=89 src= ' + imgurl  + ' onclick =  enlarge(this)>&nbsp;');             }        });     } function enlarge(el) {   var source = $(el).attr('src');    var label = $(el).attr('alt');      $('#imgdiv').css('display', 'none');            $('#bigdiv').css('display', 'block').html('<img width = 600 src= ' + source  + '><br><div class=imgtitle>' + label + '</div>')    } 

thanks advice/assistance.

you need use find target particular element

use

var label = $(el).find('img').attr('alt'); 

this corresponds element $('#imgdiv') . need find img descendant of element.


Comments

Popular posts from this blog

php - Calling a template part from a post -

Firefox SVG shape not printing when it has stroke -

How to mention the localhost in android -