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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T07:36:14+00:00 2026-05-31T07:36:14+00:00

I’ve just recently been studying JQuery to use on a personal website. Something I

  • 0

I’ve just recently been studying JQuery to use on a personal website. Something I wanted to add to the website was a blog preview feature, which uses AJAX and JSON to retrieve the title and preview text of a blog post. When a visitor clicks the blog tab, JQuery retrieves the information and is displaying the titles the way I want it to. The titles are supposed to be clickable, so that when you click a title the preview text is shown. For the most part I have this working by using JQuery’s .on() function, however for whatever reason only every other title is clickable. Here is the code:

$(document).ready(function() {

        function handleSelect(event, tab) {
            if (tab.index == 1) {
                $("#blogContent").empty();
                $.getJSON("/TimWeb/blogPreview", function(data) {
                    $.each(data, function(i) {
                        $("#blogContent").append("<h3 class=head>" +
                                data[i].blogTitle + "</h3>" +
                                "<p>" + data[i].blogBody + "</p>");

                        $("#blogContent .head").on("click", function() {
                            $(this).next().toggle();
                        }).next().hide();

                    });
                });
            }
        }

        var tabOpts = {
                select:handleSelect
        };

        $(".tabs").tabs(tabOpts);
    });

For a more visual description of the problem, if I have eight blog posts that are being previewed, the title for each will be rendered appropriately, with the content hidden. If I try clicking the first, third, fifth, or seventh title, nothing happens. If I click the second, fourth, sixth, or eighth titles, the post preview will appear. If I click it again, it will be hidden, as I expect it to be.

In case it causes any confusion, blogContent is the id of the div referenced by the jQuery tab for the blog section. I would greatly appreciate any advice or wisdom you could lend me!

  • 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-31T07:36:15+00:00Added an answer on May 31, 2026 at 7:36 am

    You don’t need to attach the event to each individual h3.

    .on() can be used to attach a function to an event for everything, both now and in the future, that match a selector (jQuery 1.7+).

    Try taking the .on() out of the each loop (and the function), hide the p tag via style=”display:none;” and place this after the function:

    $(document).on("click", "#blogContent .head", function(){ $(this).next().toggle(); });
    

    Something like this:

        function handleSelect(event, tab) {
            if (tab.index == 1) {
                $("#blogContent").empty();
                $.getJSON("/TimWeb/blogPreview", function(data) {
                    $.each(data, function(i) {
                        $("#blogContent").append("<h3 class=head>" +
                                data[i].blogTitle + "</h3>" +
                                "<p style='display:none;'>" + data[i].blogBody + "</p>");
                    });
                });
            }
        }
    
        // This only needs to be executed once.
        $(document).on("click", "#blogContent .head", function(){ $(this).next().toggle(); });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a jquery bug and I've been looking for hours now, I can't
I have just tried to save a simple *.rtf file with some websites and
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am trying to understand how to use SyndicationItem to display feed which is
I used javascript for loading a picture on my website depending on which small
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am reading a book about Javascript and jQuery and using one of the
I want use html5's new tag to play a wav file (currently only supported
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka

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.