Monday 15 July 2013

html - jquery change background of one element at a time -


So, I am using this function below to change the background of an element at a time. I am doing this very good work, I am getting it from here anyway, but what would I want to do when you click on the second or third child after the couple's class, then it will remove the class and return to the active class First child will add

  $ (window) .load (function () {$ ('. Innernav li: first-child A'). AddClass ('back');}); $ ("A") (function () {$ ('a'). RemoveClass ('back'); $ (this) .addClass ('back');});   

To a large extent, I would like to return it to the first-child rule when an element will be clicked the second time. The reason for this is because, on my site, when you click on one, the content below will be displayed when a different element is clicked, it will display new content and hide the last, but once again clicked, That content will return to the original content, which shows that the page is displayed when it is initially loaded. I will include that work in it, in which people have a better understanding of what is really happening. I'm not able to display toggles to work in JSFDold, but it works normally

Try checking whether the class 'back' already exists (Aka clicked before a link). If so, return to the first-child rule:

  $ (window) .load (function () {$ ('. Innernav li: first-child A'). AddClass 'back'); }); $ ("A # bg") click (function () {var isSecondClick = $ (this) .hasClass ('back'); $ ('a'). RemoveClass ('back'); if (isSecondClick) {$ ('.innernav li: First child one'). AddClass ('back');} and {$ (this) .addClass ('back');}});   



No comments:

Post a Comment