Adam Jahur Adam Jahur - 23 days ago 8
HTML Question

how to link another html page to a poster image in jquery?

var columnBlock = $('<div class="col-md-2">');
var imagePoster = $('<img>');
var selectButton = $('<a href="secondPage.html"><button class="selectButton"></button></a>');

var movieID = results[i].id;

imagePoster.attr('movie-id', movieID);
imagePoster.attr('src', 'https://image.tmdb.org/t/p/w500' + results[i].poster_path);

selectButton.text("Select Movie");
selectButton.attr('movie-id', movieID);

columnBlock.append(imagePoster);
columnBlock.append(selectButton);
$('.row').append(columnBlock);


I want to make the imagePoster link to the secondPage.html and i tired the same method as i did with the button but it takes away all the poster images on the page.

Answer

Delete this one: columnBlock.append(imagePoster);

Add this : var imagePoster_link = $('<a href="AnOtHeR.UrL">');
And this: imagePoster_link.append(imagePoster);
And this : columnBlock.append(imagePoster_link);

Just before : columnBlock.append(selectButton); (unchanged)

In short it puts your img inside an ancor element before happending it to the document.