javascript - Anchor needs twice click to perform action in js -
javascript - Anchor needs twice click to perform action in js -
i calling tab alter event on anchor tag click.on first time page load need twice click perform action.after moving next tab , same function work 1 click.i tried different methods didn't work.my code below :html link
<a class="btn btn-default-o pull-right btn-sm" id="checkpname">next »</a>
class="lang-js prettyprint-override">jquery(document).ready(function() { jquery("#checkpname").click(function() { if (jquery('#name').val() == '') { alert("please select product name first.") jquery('#name').focus(); jquery('#name').css('border', '1px solid red'); } else { changetab('step2'); } }); function changetab(hrf){ jquery('a.btn').each(function () { jquery(this).click(function () { //var thisid = $('#sell .tab-pane.active').attr('id'); jquery('.wizard a[data-toggle="tab"]').removeclass('current'); jquery('.wizard a[href="#' + hrf + '"]').click(); }); }); }
changing tab done on clicking twice on link.while 1 time moved next tab did same work on 1 click right way it.may can help me
the problem due way you're binding alter listener/function after click link first time, have click 1 time again trigger new click bind (and incidentally, you're adding new click bind when click sec time).
in code illustration phone call function changetag
, binds new click listener onto a
tag. removing sec click bind jquery(this).click(function () {
, initiating click should create work.
ex:
jquery(document).ready(function() { jquery("#checkpname").click(function() { if (jquery('#name').val() == '') { alert("please select product name first.") jquery('#name').focus(); jquery('#name').css('border', '1px solid red'); } else { changetab('step2'); } }); function changetab(hrf){ jquery('a.btn').each(function () { //var thisid = $('#sell .tab-pane.active').attr('id'); jquery('.wizard a[data-toggle="tab"]').removeclass('current'); jquery('.wizard a[href="#' + hrf + '"]').click(); }); } });
javascript jquery
Comments
Post a Comment