Click here to Skip to main content
15,886,067 members
Please Sign up or sign in to vote.
1.57/5 (3 votes)
hi all
in Aspx Page I Have :
XML
<asp:LinkButton ID="LinkBtn1" runat="server" CssClass="Tag" ClientIDMode="Static" Visible='<%# SetVisible(Eval("Tag1"))%>'><%# SetTag(Eval("Tag1"))%></asp:LinkButton>

and myScript is below.Why $(this) is Unknown?
C#
$('.Tag').mouseenter(function () {
    var t = $(this).html();
    var tagName2 = encodeURIComponent(t);
    $.ajax({
        url: 'Test2.aspx?Name=' + tagName2,
        success: function (data) {
            if (data == "")
                return;
            //in This Section $(this) is Unknown.Why?How To Access  $(this)
            $(this).append('<div class="TagComment2"> slm man khubam</div>');
alert('Test');//and alert Not Show!WHy?
        }
    });
Posted
Updated 14-Jun-13 2:29am
v3
Comments
Have you included the jQuery file in the aspx page?
Sunasara Imdadhusen 14-Jun-13 7:57am    
What is your problem??
Seyed Ahmad Mirzaee 14-Jun-13 8:18am    
$(this).append('<div class="TagComment2"> slm man khubam</div>');
if you Write in this Line alert('Test'); Alert is Not Show!Why?
That means it is not going to the success function.

Check your FireBug Console window of FireFox, if you see any errors or not.
Sergey Alexandrovich Kryukov 14-Jun-13 13:17pm    
A bug is found, please see my answer.
—SA

1 solution

Problem

I guess you are trying to insert the div after the LinkButton.

But you have used append method, which will append the div inside the LinkButton, which makes no sense.

And you have another problem of "this" object.
That is, when you are in Success function, it will refer to the object of Success method, not the element LinkButton.

Solution

  • So, you need to store the current object in a variable before any further operation, so that you can use that variable inside the Success function.
  • Use .insertAfter()[^] to insert any element after the LinkButton.
  • Ending brackets of mouseenter event is also missing.


The code will look something like below...
JavaScript
$('.Tag').mouseenter(function () {
    // Store element object in a variable.
    var currentElement = $(this);
    var t = currentElement.html();
    var tagName2 = encodeURIComponent(t);

    $.ajax({
        url: 'Test2.aspx?Name=' + tagName2,
        success: function (data) {
            if (data == "")
                return;
            
            // Now use currentElement here.
            $('<div class="TagComment2">slm man khubam</div>').insertAfter(currentElement);
            alert('Test');
        }
    });
}); // This brackets are missing in your code.


Suggestion

Check the FireBug Console window to check if there are any other issues or not.
 
Share this answer
 
v3
Comments
Sergey Alexandrovich Kryukov 14-Jun-13 15:29pm    
My 5, and thank you again for correcting me.
—SA
Most welcome.
Thanks Sergey Alexandrovich Kryukov... :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900