0

I'm trying to load the yt video by clicking on the link but I need two actions to happen. The problem is that I can't execute both action only one. Is there a way to do it?

<a href="tS8392pvFIw">Windows Phone</a>  //this works
<a href="#video">Windows Phone</a> // but I also need this anchor to execute

I tried this but it doesn't work:

<a href="#video" onclick="tS8392pvFIw">Windows Phone</a>
Felix
  • 37,892
  • 8
  • 43
  • 55
SamotnyPocitac
  • 401
  • 5
  • 16

1 Answers1

0

I suggest you to create a new function that do those two actions. Make a new listener in jquery for this link, pass the event with it and do a event.preventDefault() to avoid href action. Then execute your "tS8392pvFIw" and then use this function to go to your element with your id:

function goToByScroll(id){
      // Remove "link" from the ID
    id = id.replace("link", "");
      // Scroll
    $('html,body').animate({
        scrollTop: $("#"+id).offset().top},
        'slow');
}

I took this code in this question: scroll to a div using jquery Take a look.

Community
  • 1
  • 1
SteamFire
  • 367
  • 2
  • 14
  • the anchor is actually for the tab not for scrolling down to a specific place. I tried to create an function but it doesn't work for the YT video embed. – SamotnyPocitac Feb 11 '14 at 16:37
  • Do you have more code to show? What the code of the iframe? You want to open a new tab with the video inside? – SteamFire Feb 12 '14 at 06:38