-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
  • 577
  • 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
  • 959
  • 7
  • 19
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
  • 132,252
  • 13
  • 159
  • 168
0

Try this:

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

JSFiddle Demo

imbondbaby
  • 6,351
  • 3
  • 21
  • 54
0
<script>
$(document).ready(function(){
    var href = $('a[rel="wp-video-lightbox"]').attr('href');
    window.location.href = href;
});
</script>
MH2K9
  • 11,951
  • 7
  • 32
  • 49