javascript - .attr 'alt' displaying only the first word -


i stuck on small issue, i'm trying print image titles getting them alt tag. not working because showing first word alt.

$("#gallerythumbs .imagethumb").click(function () {     if ($(this).hasclass('active')) {         //do nothing     } else {         var newimage = $(this).attr('picurl');         $('#galleryimagelarge').attr('src', newimage);         $("#gallerythumbs .imagethumb").removeclass('active');         $(this).addclass('active');          var newtitle = $(this).attr('alt');         $('#gallerytitle').text(newtitle);     } }); 

the html code:

<div class="col-md-6 verticalcenter work" id="largegalleryimage">     <img src="<?php echo $galleryimages[0]['sizes']['large']; ?>"         alt="<?php echo $galleryimages[0]['title']; ?>"         class="img-responsive" id="galleryimagelarge" />     <p id="gallerytitle"><?php echo $galleryimages[0]['title']; ?></p> </div> 

you should escape variables passed php html, i.e. try replace:

<?php echo $galleryimages[0]['title']; ?> 

with:

<?php echo htmlspecialchars($galleryimages[0]['title']); ?> 

your $galleryimages[0]['title'] might have " symbol interpreted end of attribute value.

more info: http://php.net/manual/en/function.htmlspecialchars.php


Comments

Popular posts from this blog

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

linux - disk space limitation when creating war file -