How to implement dynamic content loading in jQuery Accordion Widget panels

0 votes
How to implement dynamic content loading in jQuery Accordion Widget panels?
Apr 3 in JQuery by Nidhi
• 14,600 points
69 views

1 answer to this question.

0 votes

Here's how to load content dynamically into jQuery UI Accordion panels:

Basic Implementation

<div id="accordion">

  <h3>Section 1</h3>

  <div data-source="section1.html"></div>

  <h3>Section 2</h3>

  <div data-source="section2.html"></div>

</div>


JavaScript Code

$(function() {

  $("#accordion").accordion({

    collapsible: true,

    beforeActivate: function(event, ui) {

      var newPanel = ui.newPanel;

      if (newPanel.is(":empty") && newPanel.data("source")) {

        newPanel.html("<div class='loading'>Loading content...</div>");

        $.get(newPanel.data("source"), function(data) {

          newPanel.html(data);

        }).fail(function() {

          newPanel.html("<div class='error'>Failed to load content</div>");

        });

      }

    }

  });

});

answered Apr 4 by anonymous

Related Questions In JQuery

0 votes
1 answer

How to implement a dynamic bootstrap 4 accordion, using Jquery

With this you can add dynamic accordion ...READ MORE

answered Jun 7, 2022 in JQuery by Edureka
• 13,690 points
4,174 views
0 votes
1 answer

How to pass parameters in GET requests with jQuery?

Hello, Here is the syntax using jQuery $.get $.get(url, data, ...READ MORE

answered Apr 28, 2020 in JQuery by Niroj
• 82,840 points
44,645 views
0 votes
1 answer

How to set cache false for getJSON in jQuery?

Hello @kartik, Your code just needs a trigger ...READ MORE

answered May 12, 2020 in JQuery by Niroj
• 82,840 points
1,194 views
+1 vote
2 answers

How to set cache false for getJSON in jQuery?

You can't pass any configuration parameters to ...READ MORE

answered Oct 7, 2020 in JQuery by Amit
• 140 points
3,187 views
0 votes
1 answer

How to check if button is disabled in jQuery Mobile?

Hello, you can try $("#deliveryNext").is(":disabled") The following code works for ...READ MORE

answered May 29, 2020 in JQuery by Niroj
• 82,840 points
4,871 views
0 votes
1 answer

How to prevent multiple selection in jQuery UI Selectable plugin?

Hii @kartik, What I did is that I allow multiple ...READ MORE

answered May 30, 2020 in JQuery by Niroj
• 82,840 points
1,458 views
0 votes
1 answer

Which is faster: Using bootstrap CDN or downloaded

CDNs deliver faster loading speeds for readers. Files ...READ MORE

answered Jun 30, 2022 in Web Development by rajatha
• 7,680 points
1,922 views
0 votes
1 answer

What are the best practices for using jQuery’s closest() and parents() functions for DOM traversal?

Use .closest() for the Nearest Match Efficient for ...READ MORE

answered Dec 17, 2024 in Java-Script by Navya
141 views
0 votes
1 answer

How can I use jQuery to select all elements with multiple CSS classes?

You can use the following syntax to ...READ MORE

answered Dec 17, 2024 in Java-Script by Navya
105 views
0 votes
1 answer

How to add popper.js in React?

Install Popper.js via npm (npm install @popperjs/core), ...READ MORE

answered Feb 23 in Node-js by Kavya
205 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP