Reputation: 329
I use this jquery code to start loading videos after user clicks on thumbnail. Html code with video is commented out and after click, jquery removes comments and video is played automatically due to parameter included in url.
$(document).ready(function(){
$("a.video-in-link").one('click',function(){
var anchor = $(this);
anchor.html(anchor.html().replace('<!--','').replace('-->',''));
anchor.removeAttr('href');
return false;
})
})
On my page I use also javascript tabs with various content.
Problem: After visiting another tab on this page and returning to the tab with videos, videos start to play automatically again. It is probably because the comments are removed and videos are set to play automatically. Is it possible to add to this code some sort of check if comments exists every time the page is visited from another tab? Or is there any better solution? Thank you
Upvotes: 0
Views: 116
Reputation: 457
just try
$(document).ready(function(){
var str="<!--";
if($("a.video-in-link").indexOf(str)==-1)
{
//not found
//then add comment and href
}
else
{
//found
}
}
if u have multiple href then
$("a.video-in-link").each(function()
{
var item=$(this);
if($(item).indexOf(str)==-1)
{
}
});
Upvotes: 0
Reputation: 415
There is an error with your code, should be "on" not "one"
$(document).ready(function(){
$("a.video-in-link").on('click',function(){
var anchor = $(this);
anchor.html(anchor.html().replace('<!--','').replace('-->',''));
anchor.removeAttr('href');
return false;
})
})
Upvotes: 1