Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JQuery onchange in tabs event

Does anyone know how to fire an event when I change from one tab to the other in JQuery?

for example:

<li><a href="#tab-1" onclick="submitForm();" onchange="myJSHere();">Tab</a></li>
like image 966
Satch3000 Avatar asked Oct 28 '11 10:10

Satch3000


4 Answers

My Solution is Click Event Listener.

Solution:

$('.nav-tabs li').click(function () { 
  alert('Tab Clicked');
});

Complete Solution with HTML.

HTML

<div id="tabs">
        <ul class="nav nav-tabs">
            <li class="active"><a data-toggle="tab" href="#home">Home</a></li>
            <li><a data-toggle="tab" href="#menu1">Menu 1</a></li>
            <li><a data-toggle="tab" href="#menu2">Menu 2</a></li>
        </ul>

    <div class="tab-content">
        <div id="home" class="tab-pane fade in active">
            <h3>HOME</h3>
            <p>Some content.</p>
        </div>
        <div id="menu1" class="tab-pane fade">
            <h3>Menu 1</h3>
            <p>Some content in menu 1.</p>
        </div>
        <div id="menu2" class="tab-pane fade">
            <h3>Menu 2</h3>
            <p>Some content in menu 2.</p>
        </div>
    </div>
</div>

Script

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script>
$('.nav-tabs li').click(function () { 
  alert('Tab Clicked');
});
like image 175
SumitK Avatar answered Sep 23 '22 15:09

SumitK


Work for me

HTML:

<div id="tabs">
    <ul class="nav nav-tabs">
        <li class="active"><a data-toggle="tab" href="#home">Home</a></li>
        <li><a data-toggle="tab" href="#menu1">Menu 1</a></li>
        <li><a data-toggle="tab" href="#menu2">Menu 2</a></li>
    </ul>

    <div class="tab-content">
        <div id="home" class="tab-pane fade in active">
            <h3>HOME</h3>
            <p>Some content.</p>
        </div>
        <div id="menu1" class="tab-pane fade">
            <h3>Menu 1</h3>
            <p>Some content in menu 1.</p>
        </div>
        <div id="menu2" class="tab-pane fade">
            <h3>Menu 2</h3>
            <p>Some content in menu 2.</p>
        </div>
    </div>
</div>

Script

<script src="https://code.jquery.com/ui/1.12.0/jquery-ui.js"></script>
<script>
    $("#tabs").tabs({
        activate: function(event, ui) {
            alert("PRESSED TAB!");
        }
    });
</script>
like image 30
Tiago S Avatar answered Nov 02 '22 00:11

Tiago S


jQuery ui ???

$("#tabs").tabs({
    select: function(event, ui) {
        alert("PRESSED TAB!");
    }
});
like image 27
Marco Johannesen Avatar answered Nov 01 '22 22:11

Marco Johannesen


$(function() {
    $( "#tabs" ).tabs({ activate: function(event ,ui){
                    //console.log(event);
                    //alert(  ui.newTab.index());
        alert( ui.newTab.attr('li',"innerHTML")[0].getElementsByTagName("a")[0].innerHTML);
        //alert( this.text);
                } });
like image 18
Milind Morey Avatar answered Nov 01 '22 22:11

Milind Morey