-2

I have a link and would like to auto click it to open an popup windows to play an video.

The link is like as

<a rel="wp-video-lightbox" href="https://www.youtube.com/watch?v=xxxxxxx&amp;width=640&amp;height=480" title="">Watch Movie</a>

How do I do it in jQuery?

Best regards,

Kelvin

Kelvin
  • 557
  • 7
  • 25

4 Answers4

2

Just do something like this:

<a rel="wp-video-lightbox" href="" title="">Watch Movie</a>

$(document).ready(function(){
  $('a[rel="your-rel"]').get(0).click();trigger('click');
});

UPDATE: updated the code for your needs, now you only have to change the "rel" attribute.

JiFus
  • 939
  • 7
  • 17
1

You can use Attribute Equals Selector [name="value"] to get element then use .get() to refer to DOM element.

Use

$(document).ready(function() {
    $('a[rel="wp-video-lightbox"]') //Get element using rel attribute
        .get(0) //Get DOM element
        .click(); //Click
});
Satpal
  • 129,808
  • 12
  • 152
  • 166
0

Try this:

$(document).ready(function(){
    var rel = $('a[rel="wp-video-lightbox"]');
        rel[0].click();
});

JSFiddle Demo

imbondbaby
  • 6,253
  • 3
  • 18
  • 53
0
<script>
$(document).ready(function(){
    var href = $('a[rel="wp-video-lightbox"]').attr('href');
    window.location.href = href;
});
</script>
MH2K9
  • 11,772
  • 7
  • 31
  • 48