Question

I know there are some threads with same question, but mine is a bit different.

I know how to activate tab on element click. There are many answers about it. For example, this one.

I need to activate tab not on click, but on page load depending on GET query. I am getting param from GET query and then want to activate tab depending on this param.

<?
$type = $_GET['type'] ? $_GET['type'] : '0';
?>
<script>
$(function() {
    var type = <?=$type; ?>;

    if(type == 1)
    {
        // activate 1 tab
    } 
    else-if(type == 2)
    {
        // activate 2 tab
    }
    else
    {
        // activate 2 tab
    }
</script>

It is just an example.

So the question is: how to use tabs method without selector. ~ like there:

$.tabs({
    active: type
});

(This one not working)

Was it helpful?

Solution

You can select the tabs simply triggering the click action on the desidered tab:

$("#tabId").trigger("click");

OTHER TIPS

Try this one:

$('#your_tab_id').tabs({ selected: <?php echo $type; ?> });
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top