1

Here's a snippet of the JS:

...
$(this).load('html_fragment.html', function(data) {
    console.log(data);
    $(data).find('.accordion').accordion();
});
...

here's the content of the document I'm loading (html_fragment.html):

<form>
    <div class="accordion">
        <h3><a href="#">Section 1</a></h3>
        <div>
            <p>
                Mauris mauris ante, blandit et, ultrices a, suscipit eget, quam. Integer
                ut neque. Vivamus nisi metus, molestie vel, gravida in, condimentum sit
                amet, nunc. Nam a nibh. Donec suscipit eros. Nam mi. Proin viverra leo ut
                odio. Curabitur malesuada. Vestibulum a velit eu ante scelerisque vulputate.
            </p>
        </div>
        <h3><a href="#">Section 2</a></h3>
        <div>
            <p>
                Sed non urna. Donec et ante. Phasellus eu ligula. Vestibulum sit amet
                purus. Vivamus hendrerit, dolor at aliquet laoreet, mauris turpis porttitor
                velit, faucibus interdum tellus libero ac justo. Vivamus non quam. In
                suscipit faucibus urna.
            </p>
        </div>
        <h3><a href="#">Section 3</a></h3>
        <div>
            <p>
                Nam enim risus, molestie et, porta ac, aliquam ac, risus. Quisque lobortis.
                Phasellus pellentesque purus in massa. Aenean in pede. Phasellus ac libero
                ac tellus pellentesque semper. Sed ac felis. Sed commodo, magna quis
                lacinia ornare, quam ante aliquam nisi, eu iaculis leo purus venenatis dui.
            </p>
            <ul>
                <li>List item one</li>
                <li>List item two</li>
                <li>List item three</li>
            </ul>
        </div>
        <h3><a href="#">Section 4</a></h3>
        <div>
            <p>
                Cras dictum. Pellentesque habitant morbi tristique senectus et netus
                et malesuada fames ac turpis egestas. Vestibulum ante ipsum primis in
                faucibus orci luctus et ultrices posuere cubilia Curae; Aenean lacinia
                mauris vel est.
            </p>
            <p>
                Suspendisse eu nisl. Nullam ut libero. Integer dignissim consequat lectus.
                Class aptent taciti sociosqu ad litora torquent per conubia nostra, per
                inceptos himenaeos.
            </p>
        </div>
    </div>
</div><!-- end accordion -->


    <div id="horizontal">
        <p>horizontal test data</p>
    </div><!-- end horizontal -->
</form>

Problem?: the Jquery UI accordion function does not seem to work on the wrapped object after it's been loaded. Is there a way perform JS on the returned html fragment during the callback?

1
  • Why don't you load the html into a dom element first, like a div ? Commented Sep 1, 2011 at 21:37

1 Answer 1

1

by the time you get to the line

$(data).find('.accordion').accordion();

is the html fragment in the DOM? if so then don't find the accordinon in the data, find it in the DOM

$('body').find('.accordion').accordion();

use body or whatever your container is.

Sign up to request clarification or add additional context in comments.

2 Comments

You don't need the find. it would just be $('.accordion').accordion()
Yeah, I agree. My thought was that maybe the load inserted a copy/clone into the DOM. Therefore working with data would would be working with a detached fragment.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.