---
title: "How to Linking different elements together"  
description: "How to Linking different elements together"  
author: "Anonymous User"  
published: 2015-01-20  
updated: 2015-01-20  
canonical: https://www.mindstick.com/forum/12882/how-to-linking-different-elements-together  
category: "javascript"  
tags: ["jquery", "html", "css"]  
reading_time: 1 minute  

---

# How to Linking different elements together

I [am trying](https://answers.mindstick.com/qa/36834/which-two-programming-languages-should-i-master-in-if-i-am-trying-to-get-into-google-or-facebook) to link several different [elements](https://www.mindstick.com/forum/1440/wpf-button-with-multiple-text-elements) [together](https://yourviews.mindstick.com/view/80819/live-in-relationship-protecting-the-right-to-live-together) so that one specific [class](https://www.mindstick.com/blog/165/generic-class-in-c-sharp) element can activate an [action](https://www.mindstick.com/forum/155752/what-is-action-result-with-its-types) on another specific class element (for [instance](https://www.mindstick.com/forum/155658/testing-connection-to-cloud-sql-instance-with-a-mysql-client-from-vm-instance), if .ph5 is clicked, .art5 will be visible)

This is what I have so far:

```
var back = [$(".art1"), $(".art2"), $(".art3"),
$(".art4"), $(".art5"), $(".art6"), $(".art7"),
$(".art8"), $(".art9")];var front = [$(".ph1"), $(".ph2"), $(".ph3"),
$(".ph4"), $(".ph5"), $(".ph6"), $(".ph7"),
$(".ph8"), $(".ph9")]; $('front').click(function(e) {  var clicked = $(e.clicked);  for (var i = 0; back.length;i++) {    if (clicked.is(front[i]))
{      back[i].show();    }  }});
```

Unfortunately, this doesn't seem to work for me. Is there [something wrong](https://www.mindstick.com/forum/12790/something-wrong-with-gridview) with my code and/or is there a better way to "link" [multiple classes](https://www.mindstick.com/forum/159384/how-can-i-select-an-element-with-multiple-classes-in-jquery) together?

## Replies

### Reply by Mark Devid

If you gave them all the same common class it is even simpler. You can get an index from a collection of elements using index() and use eq() to match another set of elements (assumes both sets in same order)

```
var $front = $('.ph'); // all have same class$front.click(function(){   var index = $front.index(this); // index of element
clicked within collection   $('.art').hide().eq(index).show();  // hide
all,then show the matching index });
```

References:


---

Original Source: https://www.mindstick.com/forum/12882/how-to-linking-different-elements-together

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
