html - Jquery, activate script if hashtag on end of URL matches a class name -


O people, I am using a little bit of jQuery to do a live type of my portfolio when choosing different categories goes. Basically, on the script page, other and lt; Li & gt; The tag matches the content of a and

  • tag tag on the click (my menu) with the class names of the tag, the result is the portfolio item matching matches which is remaining Will show more Live sort however, I want to add the ability to add a permink to jquery to be sorted by the hashtag at the end .. For example: work.html # category1 automatically The script will set the script to hide any one of my script and the original page setup below will be greatly appreciated!

      & lt; Script & gt; $ (Document) .ready (function () {$ ('# worknavwrap p a') click (function () {$ (this) .css ('outline', 'none'); $ ('ul # worknavwrap ( '' '' '' '' '' '' '' '' '(' '' '' '' '' '' '' '' Hidden ');} and {$ (' ul # portfolio li '), if' (filter '=' 'all' ') ($ (' ul # portfolio li.hidden ') .each (function) If (! $ (This $) .hasClass (filterVal)} {$ (this) .FadeOut ('normal') AddClass ('hidden');} and {$ (this). FadeIn ('slow'). RemoveClass 'Hidden');}});} return false;})}};  
  • a
  • Category 2
  • <3>> Category 3 A & gt; & lt; / li & gt; & lt; / ul & gt; & lt; ul id = "portfolio" & gt; li class = "category 1" & gt; item 1 & lt; / Li & gt; & lt; Li class = "category 1" & gt; Item 2 & lt; / Li & gt; & Lt; Li class = "class 2" & gt; Item 3 & lt; / Li & gt; & Lt; Li class = "category 1" & gt; Item 4 & lt; / Li & gt; & Lt; Li class = "class 3" & gt; Item 5 & lt; / Li & gt; & Lt; Li class = "class 3" & gt; Item 6 & lt; / Li & gt; & Lt; Li class = "class 2" & gt; Item 7 & lt; / Li & gt; & Lt; Li class = "category 1" & gt; Item 8 & lt; / Li & gt; & Lt; / Ul & gt;
  • Do this:

      if (window. Location.hash) {$ ('# worknavwrap a [href =' + window.location.hash + ']'). Click (); }  

    This & lt; A & gt; Element with href hash matching attribute, and its & lt; A & gt; Elements like:

    for code will be better to provide features. > & Lt; Ul id = "worknavwrap" & gt; & Lt; Li & gt; & Lt; An id = "category 1" href = "# class 1" & gt; Category 1 & lt; / A & gt; & Lt; / Li & gt; & Lt; Li & gt; & Lt; An id = "category 2" href = "# class2" & gt; Category 2 & lt; / A & gt; & Lt; / Li & gt; & Lt; Li & gt; & Lt; An id = "category 3" href = "# class 3" & gt; Category 3 & lt; / A & gt; & Lt; / Li & gt; & Lt; / Ul & gt;

    Then you can do this:

      if (window.location.hash) {$ (window.location.hash). Click (); }  

    By the way, to match your code to your HTML, you need it:

      $ ('# worknavwrap li a '). Click (function () {...  

    instead of:

      $ ('# worknavwrap p a'). {.. ..  

    Anything:

      var filterVal = $ (this) .text (). ToLowerCase (). Replace ('', ' ');  

    instead of:

      var filterVal = $ (this) .text (). ToLowerCase (). Replace (' ',' _ ');  

    Comments

    Popular posts from this blog

    c# - sqlDecimal to decimal clr stored procedure Unable to cast object of type 'System.Data.SqlTypes.SqlDecimal' to type 'System.IConvertible' -

    Calling GetGUIThreadInfo from Outlook VBA -

    Obfuscating Python code? -