I try to create a javascript to click on the link(id="bigPicLink") once the page load but it not working. New in javascript here. Please help. Thank you.
<?php
// display modal
if (isset($_GET[id]) && $_GET[id] != "" ) {
$result = mysqli_query($dbc, "SELECT * FROM tattoo WHERE `productno` = '$_GET[id]'");
$tattoo = mysqli_fetch_assoc($result);?>
<a href="#" id="bigPicLink" title="title" data-toggle="modal" data-target="#bigPic" data-title="<?php echo $tattoo['title'];?>" data-id="<?php echo $tattoo['productno'];?>" data-price="<?php echo $tattoo['price'];?>" data-picturebig="../mainpic/<?php echo $tattoo['picture'];?>">adasdsada</a>
<?php
echo "<script type='text/javascript'>
$(document).ready(function(){
$('#bigPicLink').click();
document.getElementById('bigPicLink').click();
});
</script>";
} ?>
Translate for @mitogh answer :)
$( document ).ready(function() {
$('#bigPicLink').trigger('click')
});
Maybe when you was calling $('#bigPicLink').click()
it wasn't create in DOM, so DOM cannot know #bigPicLink
is what?
You can try
$(document).ready(function() {
setTimeout(function() {
$('#bigPicLink').click();
}, 1000);
});
or needn't $(document).ready
just only setTimeuut
setTimeout(function() {
$('#bigPicLink').click();
}, 1000);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.