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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T22:51:47+00:00 2026-06-10T22:51:47+00:00

This is my markup: <a href=# class=reviews id=like rel=popover data-content= data-placement=right data-original-title=Like episode> <i

  • 0

This is my markup:

<a href="#" class="reviews" id="like" rel="popover" data-content="" data-placement="right" data-original-title="Like episode">
    <i class="icon-thumbs-up"></i> 
    Loved it
</a>(<span id="episode_likes">{{ episode_likes }}</span>

And this is the JavaScript:

$('a.reviews#like').click(function(e){
    var element = $(this);
    $.ajax({
        url: '/episoderatings/like/',
        type: 'POST',
        dataType: 'json',
        data: {
            csrfmiddlewaretoken: '{{ csrf_token }}',
            episode_number: current,
            story: current_story
        },
        success: function(response){
            if(response=='You have liked this episode'){
                $('span#episode_likes').text(parseInt($('span#episode_likes').text())+1);
            }
            $(element).attr('data-content',response);
            $(element).popover();
        }
    });
    e.preventDefault();
});

The problem is when I click on ‘like’ button, the popover doesn’t show up on the first click so I miss the important response whether I’ve liked the page or not. When I click on the ‘like’ button, the second time popover shows up and it then maintains its toggle behaviour from there onwards. Any ideas?

  • 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-10T22:51:49+00:00Added an answer on June 10, 2026 at 10:51 pm

    When you first click on your link, there is no popover initialized yet, that could be shown. You initialize the popover with the call to $(element).popover();. So, your code initializes the popover after the click on the link and nothing is shown the first time. The second time you click it, the popover is there and can be shown.

    You must make the call to .popover() before the link is clicked. In your case

    $('a.reviews#like')
        .popover({trigger: 'manual'})
        .click(function(e){
            var element = $(this);
            $.ajax({
                url: '/episoderatings/like/',
                type: 'POST',
                dataType: 'json',
                data: {
                    csrfmiddlewaretoken: '{{ csrf_token }}',
                    episode_number: current,
                    story: current_story
                },
                success: function(response){
                    if(response=='You have liked this episode'){
                        $('span#episode_likes').text(parseInt($('span#episode_likes').text())+1);
                    }
                    $(element).attr('data-content',response).popover('show');
                }
            });
            e.preventDefault();
        });
    

    should do the trick.

    Notice the call to .popover({trigger: 'manual') in line 2. That initializes the popover and disables that it appears at once after you clicked. That wouldn’t be helpful, since you set its content in the AJAX callback, and no sooner the popover can be shown. So, in the callback, you must now call .popover('show') manually, after you have set the data-content attribute.

    One more thing: You have to call .popover('hide') at some point after you showed the popover. It will not disappear when you click on the link again, since then the AJAX call is only triggered once more and .popover('show') is called again. One solution I can think of is adding a class to the link when the popover is active and check for that class on each click. If the class is there, you can just call .popover('hide') and remove the class, else do your AJAX call. I created a small jsfiddle to show what I mean.

    For more info look at the docs.

    Hope that helps.

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

Sidebar

Related Questions

I have this markup: <ul><li id=link-notifications> <ul class=list-notifications style=display:none> <li><a href=/link/to>Item 1</a></li> </ul> </li>
I have this markup: <div id=slider1> <div class=ui-slider ui-slider-horizontal ui-widget ui-widget-content ui-corner-all> <a style=left:
I have, for example, markup like this <div id=content> <p>Here is some wonderful text,
I have an href image in this markup. <div class=imgdiv> <a class=imga href=http://destination.com> <img
I have this markup: <div class=myToggledDiv> <div>content</div> </div> <div style=margin-top: 10px;> content </div> Via
I have this type of markup: <div class=box href=pic-gallery/img01.jpg> <div>----------</div> </div> Now as I
I have this href defined in my markup: foreach (Car car in Model.Cars) {
Given this markup: // Calendar.html?date=1/2/2003 <script> $(function() { $('.inlinedatepicker').datepicker(); }); </script> ... <div class=inlinedatepicker
After creating a div on the fly with this markup: $('.circuit').prepend(<div class='component' draggable='true'>TRANSISTOR</div>); It
Here is my markup: <ul class=tab1> <li><a href=http://site.com/some.html?param=1></li> <li><a href=http://site.com/some.html?param=2></li> <li><a href=http://site.com/some.html?param=3></li> ... </ul>

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.