Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I suggest using <a href="http://www.w3schools.com/jsref/met_doc_getelementbyid.asp" rel="nofollow">getElementById</a> method. Add id attribute to <code>div</code> and handle <code>onClick</code> event.</p> <pre><code>&lt;script type="javascript"&gt; function onAClicked() { var div = document.getElementById("hiddenDivId"); //do whatever you want to div. } &lt;/script&gt; .... &lt;p&gt;&lt;a href="#" class="showDivLink" onClick="onAClicked"&gt;click to show/hide div&lt;/a&gt;&lt;/p&gt; &lt;div class="hiddenDiv" id="hiddenDivId"&gt; &lt;p&gt;Text within hidden div.&lt;/p&gt; &lt;/div&gt; </code></pre> <p><strong>UPD:</strong> if there can be a large number of links with div I suggest using <code>this</code> var. You should do something like the following</p> <pre><code>&lt;script type="javascript"&gt; function onAClicked(id) { var div = document.getElementById("hiddenDivId" + id); //do whatever you want to div. } &lt;/script&gt; .... &lt;p&gt;&lt;a href="#" class="showDivLink" id="1" onClick="onAClicked(this.id)"&gt;click to show/hide div&lt;/a&gt;&lt;/p&gt; &lt;div class="hiddenDiv" id="hiddenDivId1"&gt; &lt;p&gt;Text within hidden div.&lt;/p&gt; &lt;/div&gt; &lt;p&gt;&lt;a href="#" class="showDivLink" id="N" onClick="onAClicked(this.id)"&gt;click to show/hide div&lt;/a&gt;&lt;/p&gt; .... &lt;div class="hiddenDiv" id="hiddenDivIdN"&gt; &lt;p&gt;Text within hidden div.&lt;/p&gt; &lt;/div&gt; </code></pre> <p>UPD2: and even more, you can use <code>window.event</code></p> <pre><code>&lt;script type="javascript"&gt; function onAClicked() { var e = window.event, obj = e.target || e.srcElement, id = e.id, div = document.getElementById("hiddenDivId" + id); //do whatever you want to div. } &lt;/script&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload