Saturday 15 August 2015

javascript - Remove focus from tab control -


I have a tab control on my page with two tabs when I click on the second tab, in the tab control The page is scrolled. I do not want to focus on tab control and should keep that page where it was. I know that this is caused by href on

  • , but if I remove href, I do not see any data.

    My HTML code is as follows:

      & lt; Div id = "tabContainer" class = "container" & gt; & Lt; Ul class = "maintabs" & gt; & Lt; Li & gt; & Lt; A href = "# tab description" class = "active" & gt; Details & lt; / A & gt; & Lt; / Li & gt; & Lt; Li & gt; & Lt; A href = "# Tab Terms" & gt; Rules & lt; / A & gt; & Lt; / Li & gt; & Lt; / Ul & gt; & Lt; Div class = "tabDetails" & gt; & Lt; Div id = "tabDescription" class = "tabContents" & gt; & Lt; Div id = "divDescription" runat = "server" & gt; & Lt; / Div & gt; & Lt; / Div & gt; & Lt; Div id = "tabTerms" class = "tabContents" & gt; & Lt; Div id = "divterms" runat = "server" & gt; & Lt; / Div & gt; & Lt; / Div & gt; & Lt; / Div & gt; & Lt; / Div & gt;   

    Javascript:

      & lt; Script type = "text / javascript" & gt; $ (Document) .ready (function () {$ ("TabContents"). Hide (); $ (". TabContents: first") Show (); $ ("# tabContainer ul li a"). $ ("Active"); $ ("active"); $ ("href"); $ ("# tabContainer ul li a"). (".tabContents"). Show Hide (); $ (activeTab). Show ();});}); & Lt; / Script & gt;  

    You have to disable the default behavior of the link.

    For your click action, accept the first argument, e (for the event) and call JQuery on it will prevent the browser from following the link.

      $ ("# tabContainer ul li a"). Click (function (e) {// the browser does not handle this link - we will take it from here e.preventDefault (); // ...});   

    You can call anywhere in the function (e.g., in the end).

  • No comments:

    Post a Comment