0

I have an issue with class and ajax :

Hi have several .megavideo div on my page.

  <div class="megavideo">
    <img alt="video" src="https://i1.ytimg.com/vi/6TDQOEATSik/hqdefault.jpg">
    <a href="#nolink" onclick="javascript:play('note', 33);">
      <div class="maxiplay">
        <div class="titremaxiplay">
          CLICK TO PLAY
        </div>
        <img class="play" alt="play" src="kit/play.png">
      </div>
    </a>
  </div>

Inside the div, there a link with a javascript function. This javascript function goal is to refresh the .megavideo div around the link (and just that one)

My function :

function play(what, who){
    $.ajax({
        type: "POST",   
        url: "launchvideo.php",
        data: "what="+what+"&who="+who,
        cache: false,
        success: function(html){
        $(".megavideo").html(html);
      }
    });
}

For now, logically the function refresh every .megavideo divs. How can i use (this) on my function to target only the .megavideo link parents ?

The closest answer i found here is that : Get ID of clicked on element in function But it's not exactly what i'm looking for.

Thanks everyone ! Thomas

2 Answers 2

3

Try

<div class="megavideo">
    <img alt="video" src="https://i1.ytimg.com/vi/6TDQOEATSik/hqdefault.jpg" /> 
    <a href="#nolink" onclick="play(this, 'note', 33);">
        <div class="maxiplay">
            <div class="titremaxiplay">
                CLICK TO PLAY
            </div>
            <img class="play" alt="play" src="kit/play.png"/>
        </div>
    </a>

</div>

and

function play(el, what, who) {
    $.ajax({
        type: "POST",
        url: "launchvideo.php",
        data: "what=" + what + "&who=" + who,
        cache: false,
        success: function (html) {
            $(el).closest(".megavideo").html(html);
        }
    });
}
Sign up to request clarification or add additional context in comments.

Comments

1

Try

HTML

<a href="#nolink" onclick="javascript:play(this,'note', 33);">

JS

function play(that,what, who){
    $.ajax({
        type: "POST",   
        url: "launchvideo.php",
        data: "what="+what+"&who="+who,
        cache: false,
        success: function(html){
        $(that).closest(".megavideo").html(html);
      }
    });
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.