Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jquery select element by index

There is my markup:

<UL style="-moz-border-radius-bottomleft: 0; -moz-border-radius-bottomright: 0" class="ui-tabs ui-tabs-nav ui-helper-reset ui-helper-clearfix ui-widget-header ui-corner-all" sizcache="3" sizset="5">
  <LI class="ui-state-default ui-corner-top" jQuery1280326216622="3" sizcache="3" sizset="5">
    <A href="#tab_1" jQuery1280326216622="4"><SPAN>Page 1n</SPAN></A>
  </LI>
  <LI class="ui-state-default ui-corner-top ui-tabs-selected ui-state-active" jQuery1280326216622="5" sizcache="3" sizset="6">
    <A href="#tab_2" jQuery1280326216622="6"><SPAN>Page 2</SPAN></A>
  </LI>
  <LI class="ui-state-default ui-corner-top" jQuery1280326216622="7" sizcache="3" sizset="7">
    <A href="#tab_3" jQuery1280326216622="8"><SPAN>Page 3</SPAN></A>
  </LI>
  <LI class="ui-state-default ui-corner-top" jQuery1280326216622="9" sizcache="3" sizset="8">
    <A href="#tab_4" jQuery1280326216622="10"><SPAN>Page 4</SPAN></A>
  </LI>
</UL>

and the js code:

  jQuery(document).ready(function() {

        jQuery(".ui-layout-center").tabs({   show: loadIframe });

        rootLayout = jQuery('#container').layout
       ({
           applyDefaultStyles: true,
           north__spacing_open: 0
       });

        jQuery("#tabs_div").tabs();
        loadIframe();
    });
function reciveDataFromPages(tabIndex, data) {
       //do some thing
}

how i can active the tab with the index: tabIndex and url : data

Any ideas???

like image 834
Harold Sota Avatar asked Dec 29 '22 09:12

Harold Sota


2 Answers

Use :eq(), eg:

$(".ui-tabs a").removeClass("active");
$(".ui-tabs a:eq("+tabIndex+")").addClass("active");

http://api.jquery.com/eq-selector/

like image 67
Andy E Avatar answered Dec 30 '22 23:12

Andy E


If you want to make a tab selected based upon the tab index returned in the function receiveDataFromPages, why can't you just do this:

$(".ui-layout-center").tabs("option", "selected", tabIndex);

I'm not sure why the URL matters in the determination of the selected tab. I may not fully understand the question, though.

Hope this helps!

like image 40
David Hoerster Avatar answered Dec 30 '22 21:12

David Hoerster