Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7165533
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T14:15:54+00:00 2026-05-28T14:15:54+00:00

Possible Duplicate: $(this) doesn't work in a function Im having a problem targeting the

  • 0

Possible Duplicate:
$(this) doesn't work in a function

Im having a problem targeting the right element in my code. I have a list of thumbnails on my page, and when you click on a “I dislike this” icon the targeted video change for another one.

Here’s the HTML

<li class="videoBox recommended">
   <div class="spacer" style="display: block;"></div>
   <div class="features">
       <div>
          <a class="dislike_black" title="I dislike this" onclick="ThumbsDown(30835, 'relevance', '1');"></a>
       </div>
   </div>
   <a href="...">
   <h1>...</h1>
   <div class="information">...</div>
</li>

Ajax is:

function ThumbsDown(id,sort,page) {
$.ajax({
    url: "/change/videos/"+id+"/thumbsdown/",
    type: "POST",
    data: {
        "sort": sort?sort:"",
        "page": page?page:""
    },
    success: function(data) {
        //$("#content .videoList ul li.videoBox").html(data); // THIS IS WORKING, but replaces ALL the divs
        $(this).parent("li.videoBox").html(data); // Cant get this to work!
    }
});

What Iam doing wrong? even $(this).css(“border”,”1px solid red”) is not “working”. (I tried with background color, and color too) I dont see anything.

$(This) refers to the “a” tag where the function is called right? So im searching for his parent named videobox… Help?

So can I target

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T14:15:56+00:00Added an answer on May 28, 2026 at 2:15 pm

    You should not use onclick, you should bind it to an event, especially as you could easily make this degrade well if the user does not have ajax.

    Change your <a> tags to this:

    <a href="/change/videos/1/thumbsdown/"
        data-sort="sort"
        data-page="page"
        class="dislike_black"
        title="I dislike this"></a>
    

    jQuery event:

    $('.dislike_black').click(function(e) {
        e.preventDefault(); // Prevent link from clicking
    
        var $aTag = $(this); // I use $aTag to denote a jq object
    
        $.ajax({
            url: $aTag.attr('href'),
            type: "POST",
            data: {
                "sort": $aTag.data('sort'), // data-sort attr value
                "page": $aTag.data('page') // data-page attr value
            },
            success: function(response) {
                $aTag.closest(".videoBox").html(response);
            }
        });
    });
    

    Now it works without javascript, and you’re not using nasty onclick! Untested/no warranty.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: JavaScript function aliasing doesn't seem to work Why doesn't this work? function
Possible Duplicate: How does this “size of array” template function work? Is there any
Possible Duplicate: Access array element from function call in php instead of doing this:
Possible Duplicate: What does this mean? (function (x,y)){…}){a,b); in JavaScript I have the following
Possible Duplicate: php multi-dimensional array remove duplicate I have an array like this: $a
Possible Duplicate: Returning reference to a local variable I happened to find this code
Possible Duplicate: What’s with the love of dynamic Languages I have already read this
Possible Duplicate: Nullable types and the ternary operator. Why won’t this work? This is
Possible Duplicate: What does (function($) {})(jQuery); mean? I've seen a lot of jQuery code
Possible Duplicate: QString to char conversion I have a function (fopen in STL) that

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.