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 8913817
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T04:33:09+00:00 2026-06-15T04:33:09+00:00

I have this code in Jquery and work fine, but the only problem is

  • 0

I have this code in Jquery and work fine, but the only problem is don´t change de div on a page

   $("a[rel^='meGusta']").click(function(){
            var usuario= $(this).data('usuario');
            var idea= $(this).data('idea');
            // llamada ajax
            $.ajax({
                url: '{{path('votarIdea')}}',
                data: {user: usuario, idea: idea},
                type: 'POST',
                dataType: 'html',
                success: function(){
                    var str= $(this).text().trim();
                    if (str == 'Me gusta'){
                        $(this).text("No me gusta");
                    }else{
                        $(this).text("Me gusta");
                    }

                    $('.popularityPopularidad').load('cambioVoto.html.twig');
                }
                //error: noCambio()
            });

votarIdea function return this: <span> Popularidad:</span> {{ total }}

so I have to change this div: first

<div class="popularityPopularidad">
    <span> Popularidad:</span> {{ votaciones[idea.getId()] }}
</div>

and second

 <a href="#" rel="meGusta{{num}}" data-usuario="{{ usuario }}" data-idea= "{{idea.getId()}}">
        {% if (opc)%}
            No me gusta
        {% else%}
            Me gusta
        {% endif %}
        </a>

firebug throw this error

TypeError: context.createDocumentFragment is not a function
error source line:
[Parar en este error]   

fragment = context.createDocumentFragment();

but don´t do it. Any idea.

  • 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-06-15T04:33:11+00:00Added an answer on June 15, 2026 at 4:33 am

    I just ran into a similar problem myself, and since I could not find a solution anywhere else… here it is! (please imagine a suitably impressive drum roll)

    What is happening

    The error message is not very expressive, if not misleading. This is what it should say:

    A jQuery function received an object that is not a valid jQuery object (but should be)

    Now, it is actually not that easy to get to this point, as jQuery falls back to an “empty” object in almost all cases. However, expressions similar to the following should get you to the error reliably:

    $({}).text("asb");
    $({}).append("<p></p>");
    

    Oddly enough, these do not throw an error:

    $({}).text(); // returns ""
    $({}).html(); // returns undefined
    

    I have not dug much deeper into this, but I think it is quite safe to say that any attempt at manipulation of the DOM will throw this error if the context is not a valid jQuery object.

    The specific problem of this question is that in the ajax success function, this is not the html element, but the ajax event object. So the expression $(this) does not return a valid jQuery object, and subsequently calling $(this).text() (or most anything actually) will cause exactly this error.

    You can easily reproduce the error with the following line

    $.get("VALID URL", function(){ $(this).append("foo"); }, "text");
    

    The solution

    So what you have to do is just save the context from the click() function in an upvalue like this:

    $("a[rel^='meGusta']").click(function(){
        var usuario= $(this).data('usuario');
        var idea= $(this).data('idea');
        var self = this; // <-- NEW LINE
    
        // llamada ajax
        $.ajax({
            url: "{{path('votarIdea')}}", // <-- Syntax error (see below)
            data: {user: usuario, idea: idea},
            type: 'POST',
            dataType: 'html',
            success: function(){
                var str= $(self).text().trim(); // <-- CHANGED LINE
                if (str == 'Me gusta'){
                    $(self).text("No me gusta"); // <-- CHANGED LINE
                }else{
                    $(self).text("Me gusta"); // <-- CHANGED LINE
                }
    
                $('.popularityPopularidad').load('cambioVoto.html.twig');
            }
            //error: noCambio()
        });
    });
    

    How to find the line that really causes the error (using Firebug)

    Since the QA did not seem to know how to find the correct code line, here is a short guide:

    • Repeat the action that causes the error (or reload if it happens on page load)
    • right-click on the error and select break on this error in the context menu
    • repeat the action that caused the error
    • In the script view (Firebug should open it automatically), click on the Step out (Shift+F11) (step out) button until the script view jumps to a line that is not in jquery-*.js

    The “Syntax error”

    In the original code there was a “syntax error”. However, twig probably replaced it with different code that does not contain single quotes before the javascript actually was executed, thus the syntax error would not appear when opening the site in a browser. However, it is still a good idea to write syntactically correct code.

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

Sidebar

Related Questions

I have this jQuery code: $(document).ready(function() { $.ajax({ url: pages/+page+.php, cache: false }).done(function( html
I have this jQuery code in my JSP page (jQuery 1.7.2) : function Header()
I have this code for a JQuery a dialog for a div containing a
I have this code: jQuery: var mouseDown=false; var lastPositionX; var lastPositionY; var newX; var
OK i have this code HTML: <html> <head> <script type=text/javascript src=http://code.jquery.com/jquery-1.7.1.min.js> </script> <script type=text/javascript>
Ok, I have this code: <html> <head> <script type=text/javascript src=http://code.jquery.com/jquery-1.7.1.min.js></script> <script type=text/javascript> function get()
I have this code in jquery : $(#order_btn).click(function(){ var totalprice = $(.price_amount).text(); $(#totalprice).val(totalprice); });
I have this code in jQuery.. $(document).ready(function(){ var fieldCounter = 0; ... I have
i have this jquery code $(#eioShowLink).on('click',function(){ $(#ioEditRelatedConcepts).html(''); $.getJSON(http://localhost/Mar7ba/Ontology/getRelatedConceptsAndRelations/+conceptName+/TRUE, function(data){ var concepts = data[0]; var
I have this JQuery code working however I need to know whether how to

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.