Note that there are some explanatory texts on larger screens.

plurals
  1. POGetting the parent span title value from child node using Javascript or jQuery
    text
    copied!<p>I am reconstructing this question. I have the following HTML element structure.</p> <pre><code>&lt;li class="inner"&gt;&lt;span class="plus" id="sidehome" title="siteHome"&gt;SiteHome&lt;/span&gt; &lt;ul style="display:none"&gt; &lt;li class="inner"&gt; &lt;span class="plus" id="Middle_Content"&gt;Middle content&lt;/span&gt; &lt;ul style="display:none"&gt; &lt;li&gt; &lt;span id="editedpart" title="first div"&gt; &lt;form &gt; &lt;input type="hidden" value="1/middle_content/first_div" name="page_heri" id="t_div" class="" /&gt; &lt;input type="hidden" name="editedpart" value="first div" id="edited" /&gt; &lt;a href="#" title="edit" id="edit" onclick="showeditpage()"&gt;first div&lt;/a&gt; &lt;/form&gt; &lt;/span&gt; &lt;/li&gt; &lt;li&gt; &lt;span id="editedpart" title="second div"&gt; &lt;form&gt; &lt;input type="hidden" value="1/middle_content/first_div" name="page_heri" id="t_div" class="" /&gt; &lt;input type="hidden" name="editedpart" value="second div" id="edited" /&gt; &lt;a href="#" title="edit" id="edit" onclick="showeditpage()"&gt;second div&lt;/a&gt; &lt;/form&gt; &lt;/span&gt; &lt;/li&gt; &lt;li&gt; &lt;span id="editedpart" title="third div"&gt; &lt;form&gt; &lt;input type="hidden" value="1/middle_content/first_div" name="page_heri" id="t_div" class="" /&gt; &lt;input type="hidden" name="editedpart" value="third div" id="edited" /&gt; &lt;a href="#" title="edit" id="edit" onclick="showeditpage()"&gt;third div&lt;/a&gt; &lt;/form&gt; &lt;/span&gt; &lt;/li&gt; &lt;/ul&gt; &lt;/li&gt; </code></pre> <p>I want to be able to get title value of <code>&lt;span</code>> with <code>id=editedpart</code>, which is the immediate parent of the <code>&lt;a&gt;</code> tag when the link is clicked. I don't know how to explain it more. I will appreciate it if someone can help. Thanks.</p> <p>I used his jQuery code <code>var parent = $(this).closest("span");</code></p> <p>Here is my full showeditpage()</p> <pre><code>function showeditpage(){ var page = document.getElementById("t_div").value; var action = document.getElementById("edit").title; var parent = $(this).closest("span[id='editedpart']"); var str =parent.attr('title'); if(window.XMLHttpRequest){ xmlhttp = new XMLHttpRequest(); }else{ xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); } xmlhttp.onreadystatechange = function(){ if(xmlhttp.readyState == 4 &amp;&amp; xmlhttp.status == 200){ document.getElementById("pcontent").innerHTML = xmlhttp.responseText; } } xmlhttp.open("GET","../views/edit.php?page="+page+"&amp;action="+action+"&amp;editedpart="+str); xmlhttp.send(); </code></pre> <p>}</p> <p>it is not working that is it is not responding.</p>
 

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