jquery - On click add class current to single targeted menu item from anywhere on the website -
I only have to use jQuery to turn the class on a specific menu item, but from anywhere in the site I I want to add this link to make it effective Currently I have some jQuery citations that click on any menu item as class "on" and removed it from the previous active link.
So I have a portfolio page of portfolio links, will exit between different categories and sub categories, and currently you can click on them from anywhere on the site and on this portfolio page Goes, but currently Portoli adds the current class to the menu item.
The following are links, when any of them are clicked, they only need to influence the header menu item portfolio, which will be "Data-Goto =" 2 "and the menu below It is shown that the menu leader should start the class:
; Li class = "people" & gt; one class = "toggle PT-trigger" href = "#" data animation = "59" data-gotto = "2" data-toggle = "# people" & gt; ; & lt; / li & gt; & lt; li; C = "beauty"> a class = "toggle PT-trigger" href = "#" Data-Animation N = "59" Data-Goto = "2" Data-Toggle = "# Beauty- Fashion "> -
gt; & lt; / a & gt; & lt; / li & gt; & lt; li class = "mobile" & Gt; A class = "toggle PT-trigger" href = "#" data-animation = "59" data-gotto = "2" data-toggle = "# mobile" & gt; & Lt; / A & gt; & Lt; / Li & gt; & Lt; Li class = "special" & gt; & Lt; A class = "toggle PT-trigger" href = "#" data-animation = "59" data-goto = "2" data-toggle = "# special" & gt; & Lt; / A & gt; & Lt; / Li & gt; & Lt; / Ul & gt; & Lt; / Div & gt; The menu item should be made effective by the above links:
& lt; Class = "pt-trigger" data-animation = "52" data-goto = "2" data-toggle = "# people" & gt; & Lt; Li class = "menu" & gt; & Lt; Span & gt; Portfolio & lt; / Span & gt; & Lt; / Li & gt; & Lt; / A & gt;
Header menu structure with all menu items HTML:
& lt; Div class = "dotstyle dotstyle-tooltip pt-trigger-container" & gt; & Lt; Ul & gt; & Lt; A class = "PT-trigger" data-animation = "58" data-gotto = "1" & gt; & Lt; Li class = "menu on" & gt; & Lt; Span & gt; Home & lt; / Span & gt; & Lt; / Li & gt; ; & Lt; / A & gt; & Lt; A class = "PT-trigger" data-animation = "52" data-goto = "2" data-toggle = "# people" & gt; & Lt; Li class = "menu" & gt; & Lt; Span & gt; Portfolio & lt; / Span & gt; & Lt; / Li & gt; & Lt; / A & gt; & Lt; A class = "PT-trigger" data-animation = "51" data-goto = "3" & gt; & Lt; Li class = "menu" & gt; & Lt; Span & gt; Production & lt; / Span & gt; & Lt; / Li & gt; & Lt; / A & gt; & Lt; A class = "PT-trigger" data-animation = "48" data-goto = "4" & gt; & Lt; Li class = "menu" & gt; & Lt; Span & gt; About & lt; / Span & gt; & Lt; / Li & gt; & Lt; / A & gt; & Lt; A class = "PT-trigger" data-animation = "47" data-gotto = "5" & gt; & Lt; Li class = "menu" & gt; & Lt; Span & gt; Contact & lt; / Span & gt; & Lt; / Li & gt; & Lt; / A & gt; & Lt; A class = "PT-trigger" data-animation = "56" data-gotto = "6" & gt; & Lt; Li class = "menu" & gt; & Lt; Span & gt; Print & lt; / Span & gt; & Lt; / Li & gt; & Lt; / A & gt; & Lt; / Ul & gt; & Lt; / Div & gt;
So far, the main menu for jQuery works when clicking on the main menu link:
jQuery ("a.pt-trigger li" ). Click (function () {jQuery ("ap-triggered li"). RemoveClass ("current"); jQuery (this) .addClass ("current");});
Try it out?
$ (document). (Function () {$ ("a.pt-trigger"). Click (function () {var goto = $ (this) .data ('goto'); $ ("div.dotstyle a.pt- (" Current "); $ (" div.dotstyle a "). Eq (goto-1) .Fund ('li'). AddClass (" current ");});});
< H3> Demo check Only portfolio
and output
menu will work for this demo, only 2 sub-codes - Gedo = 2 and Goto = 3 For the menu.
If you have all your sub menus for all Goto 1,2,3,4 and 5, this will work for everyone.
Comments
Post a Comment