Note that there are some explanatory texts on larger screens.

plurals
  1. POCan't select ul and li elements in nested list
    primarykey
    data
    text
    <p>I have this code generating by jQuery, and can be n-level of ul and n-list item</p> <pre><code>&lt;ul id="criteria"&gt; &lt;li&gt; Goal &lt;img id="add_criterion" class="add_criterion" src="../images/icons/add-icon.png"&gt; &lt;ul id="1" class="criteria"&gt; &lt;li id="1"&gt; criteria 1 &lt;ul id="2" class="criteria"&gt; &lt;li id="2"&gt; criteria 1 &lt;ul id="3" class="criteria"&gt; &lt;li id="3"&gt;criteria 1&lt;/li&gt; &lt;li id="4"&gt;criteria 2&lt;/li&gt; &lt;/ul&gt; &lt;/li&gt; &lt;li id="3"&gt; criteria 2&lt;/li&gt; &lt;/ul&gt; &lt;/li&gt; &lt;li id="2"&gt; criteria 2&lt;/li&gt; &lt;/ul&gt; &lt;/li&gt; &lt;/ul&gt; </code></pre> <p>I want to remove li that corresponding to its id and level, I wrote this function where level is the id of ul and i is the id of li </p> <pre><code>function removeElementLi(i,level){ // if one list item in un order list if($("ul#criteria ul#"+level+" li").length ==1){ $("ul#criteria ul#"+level).remove(); }else{ $("ul#criteria ul#"+level+" li#"+i).remove(); } } </code></pre> <p>But it did not work, any help I appreciate it.</p> <p>I changed the function to </p> <pre><code>if($("ul[id="+level+"][class=criteria] li").length ==1){ $("ul[id="+level+"][class=criteria]").remove(); }else{ $("ul[id="+level+"][class=criteria] li#"+i).remove(); } </code></pre> <p>but for this html code</p> <pre><code> &lt;ul id="criteria"&gt; &lt;li&gt;Goal &lt;img id="add_criterion" class="add_criterion" src="../images/icons/add-icon.png"&gt; &lt;ul id="1" class="criteria"&gt; &lt;li id="1"&gt;criteria 1&lt;/li&gt; &lt;li id="2"&gt;criteria 2&lt;/li&gt; &lt;/ul&gt; &lt;/li&gt; &lt;/ul&gt; </code></pre> <p>when I start to remove the second li, it works but when I start to remove the first li it didn't work. I alert the jQuery statement </p> <pre><code>ul[id=1][class=criteria] li#1 </code></pre> <p>and the length is 2 in this case</p>
    singulars
    1. This table or related slice is empty.
    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.
 

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