How to not execute script code in a tab when using jQuery ui tab plugin

I just stumbled upon the jquery ui tabs plugin.

This is a very good implementation, but what if the current code is in place.

<div id="tabs">
    <ul>
        <li><a href="#tabs-1">tab1 </a></li>
        <li><a href="#tabs-2">tab2</a></li>

    </ul>
    <div id="tabs-1"><%System.out.println("test1");%></div>
    <div id="tabs-2"><%System.out.println("test2");%></div>
</div>

      

in this case, when the page is initially loaded, tab1 is the default tab. However, both sys out statements are executed initially. It doesn't matter what the default tab is. Ideally, the first sys output should be done when tab1 is selected and the second when tab2 is selected.

Is there a way to avoid this? Or the only way to have different pages for different tabs?

0


a source to share


1 answer


the script will execute because it is not constrained by javascript. If you have content in tabs-1

and tabs-2

that you do not want to execute until the tab is clicked, you should use the "ajax" function of this plugin. The demo site shows how to do this.



+1


a source







All Articles