get the details corresponding to particular tab on click of it

Html part:

<div class="tab-content">
    <div class="tab-pane active" id="tab2">
        <div class="row-fluid">
            <div class="span9 offset1">
                <header id="second">
                    <strong>Users</strong>
            </div>
            <div class="span2">
            <div class="tabbable" align="center">
                <ul class="nav nav-pills">
                    <li class="active"><a href="#mobile" data-toggle="tab"><strong>Mobile</strong>
                    </a>
                    </li>
                    <li><a href="#BO" data-toggle="tab"><strong>BO</strong>
                    </a>
                    </li>

                </ul>
            </div></div></div></div></div></div>

javascript part;

var users;

        $(document).ready(function() {
            jQuery.support.cors = true;
            loadUsers('mobile');
        });

        function loadUserDetails(id) {
            $.get('http:somelink' + id, function(data) {

        }


        function test(name)
        {
            alert("test");
        }

        function loadUsers(type) {


            $.get('http://some link' + type, function(data) {
                });
}

In my code i by default type is mobile i want if i click on BO tab the javascript function works according to that. How can i achieve that

Answers:

Answer

You need to add a click handler

jQuery(function($) {
    $('.tabbable ul li').click(function() {
        var id = $(this).find('a').attr('href').substring(1);
        loadUsers(id);
    })
})
Answer

You should create an event handler for that such as:

$(document).on('click', '.nav li', function() { // Clicking any li in your .nav-element

 loadType = $(this).children("a").prop("href"); 
 //parse out # from #BO
 // call loadUsers, loadUserDetails etc.

});

Tags

Recent Questions

Top Questions

Home Tags Terms of Service Privacy Policy DMCA Contact Us Javascript

©2020 All rights reserved.