DEVHIDE
        • Home (current)
        • About
        • Contact
        • Cookie
        • Home (current)
        • About
        • Contact
        • Cookie
        • Disclaimer
        • Privacy
        • TOS
        Login Or Sign up

        Not able to find out the id of the button for which a jquery function was called?

        728 Views Asked by user3638694 At 17 June 2014 at 00:17 2025-12-06T09:12:16.354000

        I have two buttons in my Twitter Bootstrap wizard :-

        <div class="form-actions">
            <div class="row">
                <div class="col-sm-12">
                    <ul class="pager wizard no-margin">
                        <!--<li class="previous first disabled">
                        <a href="javascript:void(0);" class="btn btn-lg btn-default"> First </a>
                        </li>-->
                        <li class="previous disabled">
                                <a id="prev" href="javascript:void(0);" class="btn btn-lg btn-default"> Previous </a>
                        </li>
                        <!--<li class="next last">
                        <a href="javascript:void(0);" class="btn btn-lg btn-primary"> Last </a>
                        </li>-->
                        <li class="next" id="skip">
                                <a id="skip" href="javascript:void(0);" class="btn btn-lg txt-color-darken"> Skip </a>
                        </li>
                        <li class="next" id="next">
                                <a id="next" href="javascript:void(0);" class="btn btn-lg txt-color-darken"> Next </a>
                        </li>
                         <li class="next finish" style="display:none;"><a href="javascript:;">Finish</a></li>
                         <input type='button' class='btn button-last btn-default' style="display:none;" name='last' value='Skip GG setup' />
                    </ul>
                </div>
            </div>
        </div>
        

        So, the Bootstrap wizard has a function called onNext. Now in this function I am trying to find out which button the user clicked on to trigger this event. I tried something as shown in the code below but it doesn't really work.

        $('#bootstrap-wizard-1').bootstrapWizard({
            'tabClass': 'form-wizard',
            'onNext': function (tab, navigation, index) {
                $("li.next").click(function() {
                    var id = "";
                    id = this.id; // or alert($(this).attr('id'));
                    alert(id);
                });
            });
        });
        
        jquery twitter-bootstrap twitter-bootstrap-wizard
        Original Q&A
        2

        There are 2 best solutions below

        4
        Ricardo Nuñez Ricardo Nuñez On 17 June 2014 at 00:30 BEST ANSWER

        Your need to remove the click handler function. You can get the index of the clicked tab. Your HTML is not accurate or not complete. Check the documentation.

        Check this jsfiddle example.

        UPDATE: This way you get the ID. Jsfiddle

        $('#bootstrap-wizard-1').bootstrapWizard({
            'tabClass': 'form-wizard',
            'onNext': function (tab, navigation, index) {
                //
            }
        });
        
        $("li.next").click(function(event) {
            console.log(event.target.id);   // get the id
        });
        
        0
        isherwood isherwood On 17 June 2014 at 00:36

        I can't get to the Wizard docs right now, but I think this is what you'd need to do:

        'onNext': function (tab, navigation, index) {
            var id = $(tab).attr('id');
            alert(id);
        }
        

        If that doesn't work, you can probably use the index to get it:

        'onNext': function (tab, navigation, index) {
            var id = $('.wizard > li').eq(index).attr('id');
            alert(id);
        }
        

        Should probably put an ID on the ul to avoid ambiguity with the selector.

        Related Questions in JQUERY

        • How to sort these using Javascript or Jquery Most effectively
        • Ajax jQuery firing multiple time display event for the same result
        • .hover() seems to overwrite .click()
        • Check for numeric value with optional commas javascript
        • Extending Highmaps Side Effect
        • Array appending after each onclick and loop in javascript
        • how can i append part of a table based on how many tr it has?
        • Play multiple audio files in a slider
        • Remove added set of rows
        • Access property of an object of type [Model] in JQuery
        • AJAX PHP - Reload div after submit
        • proengsoft/laravel-jsvalidation ReferenceError: jQuery is not defined
        • when a checkbox is checked how to display a different hidden element using javascript
        • Get jquery error Uncaught RangeError: Maximum call stack size exceeded
        • Removing only the closest thead on table filtering

        Related Questions in TWITTER-BOOTSTRAP

        • UIWebView Screen Fitting Issue
        • Website zoomed out on Android default browser
        • Twitter Bootstrap horizontal form elements on a line
        • My navbar is not expanding after collapse
        • Reload List after Closing Modal
        • Overwrite Bootstrap style for a single page
        • UI.Bootstrap Angular Typeahead and Firebase Array
        • Bootstrap - Fixed navbar doesn't do what's expected?
        • Bootstrap NavBar with no content on small screens
        • Bootstrap Dropdown Button Problems
        • ScrollBar not showing up - BootStrap
        • Bootstrap flip card with css3 transform
        • bootstrap grid layout questions
        • How do I make jquery events work in a bootstrap modal with dynamic content and selectors?
        • Using GLYPHICONS's free pngs with classes

        Related Questions in TWITTER-BOOTSTRAP-WIZARD

        • Routing issue from Wizard tab page to normal page
        • Using bootstrapValidator in Twitter Bootstrap Wizard
        • twitter-bootstrap-wizard active tab not working on load
        • Bootstrap Wizard next event works only once
        • How to submit form data to php using Twitter Bootstrap Wizard
        • ignore option of jquery validate crashes my bootstrap wizard
        • Twitter bootstrap wizard skip steps during onnext
        • Issue removing duplicate val() in :checked .map function
        • Disable multiple tabs at once
        • How to execute a function after modal open?
        • Cannot validate single tab per time
        • Not able to find out the id of the button for which a jquery function was called?
        • How do I place all properties of Javascript object into another object?
        • twitter bootstrap wizard: multiple events handling does not work
        • Twitter bootstrap wizard TypeError: container is undefined

        Trending Questions

        • UIImageView Frame Doesn't Reflect Constraints
        • Is it possible to use adb commands to click on a view by finding its ID?
        • How to create a new web character symbol recognizable by html/javascript?
        • Why isn't my CSS3 animation smooth in Google Chrome (but very smooth on other browsers)?
        • Heap Gives Page Fault
        • Connect ffmpeg to Visual Studio 2008
        • Both Object- and ValueAnimator jumps when Duration is set above API LvL 24
        • How to avoid default initialization of objects in std::vector?
        • second argument of the command line arguments in a format other than char** argv or char* argv[]
        • How to improve efficiency of algorithm which generates next lexicographic permutation?
        • Navigating to the another actvity app getting crash in android
        • How to read the particular message format in android and store in sqlite database?
        • Resetting inventory status after order is cancelled
        • Efficiently compute powers of X in SSE/AVX
        • Insert into an external database using ajax and php : POST 500 (Internal Server Error)

        Popular # Hahtags

        javascript python java c# php android html jquery c++ css ios sql mysql r reactjs

        Popular Questions

        • How do I undo the most recent local commits in Git?
        • How can I remove a specific item from an array in JavaScript?
        • How do I delete a Git branch locally and remotely?
        • Find all files containing a specific text (string) on Linux?
        • How do I revert a Git repository to a previous commit?
        • How do I create an HTML button that acts like a link?
        • How do I check out a remote Git branch?
        • How do I force "git pull" to overwrite local files?
        • How do I list all files of a directory?
        • How to check whether a string contains a substring in JavaScript?
        • How do I redirect to another webpage?
        • How can I iterate over rows in a Pandas DataFrame?
        • How do I convert a String to an int in Java?
        • Does Python have a string 'contains' substring method?
        • How do I check if a string contains a specific word?
        .

        Copyright © 2021 Jogjafile Inc.

        • Disclaimer
        • Privacy
        • TOS
        • Homegardensmart
        • Math
        • Aftereffectstemplates