Connect- Highlight multiple items when any item in the list is clicked


/ Published in: JavaScript
Save to your folder(s)

Connects multiple items on a page on click by pulling arrays of ids from the json


Copy this code and paste it in your HTML
  1. Json:
  2. "connections":[
  3. ["button0","financials_li_0"],
  4. ["button1"],
  5. ["button2","order_fulfillment_li_0"],
  6. ["button3"],
  7. ["button4"],
  8. ["button5","order_fulfillment_li_1","material_management_li_0"]
  9.  
  10. ]
  11.  
  12.  
  13.  
  14. javascript:
  15. //add and removes the focus class on click, define groups in the Json 'connections'
  16. function connect(array) {
  17. $.each(array, function(index,value) {
  18. $("#"+value).click(function(){
  19. $("div,li").removeClass("focusClass");
  20. $.each(array, function(index,value ) {
  21. $("#"+value).addClass("focusClass");
  22. });
  23. });
  24. });
  25. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.