1

So I have this table:

<table id = "editor">
  <tr>
  <tr class= "numberedListElement>
     <td name = "aaa" ... .</td>
     <td name = "b" ... .</td>
     <td class="iconsType" title="Numbered list element">
         <div class="iconsDiv">
            <input type="button" class="numberedList1" title="nl" id="numberedL">
            **<input type="button" class="numberedList1b" title="list" id="numbL">**
            <input type="button" class="bulletList1" title="nl" id="bulletL">
          </div>
         <input type="button" class="letteredList1" title="ll" id="letteredL"></td>
   </tr>
   <tr>
 </table>

So I need to select and delete that input.

I tried this :

$('#editor tr.numberedListElement td:last-child input')

but it returns blank.

5
  • what the problem if you have ID`s of elements? $("#letteredL").remove() Commented May 12, 2014 at 8:10
  • You have an extra <tr> element in there. I'm not sure that is what you intended to do. Commented May 12, 2014 at 8:13
  • The problem is you forgot " at the end of class attr. <tr class="numberedListElement"> should fix but consider Lix's answer. Commented May 12, 2014 at 8:17
  • @deadulya you are right, but i have multiple such tr-s <tr class= "numberedListElement> with the same id-s. I need somehow to generate them uniquely. Thanks Commented May 12, 2014 at 8:24
  • @alex1111 so you can identified you needed tr $(".numberedListElement") and then find you id in it $(".numberedListElement")[5].find("#letteredL"). it is not very good style coding, cause ID`s must be unique, if they are not you should fix it. Commented May 12, 2014 at 8:48

3 Answers 3

3

The easiest thing to do here would be to access the element directly using the id selector.

Description: Selects a single element with the given id attribute.

The code would look like this:

$( "#numbL" ).remove();

id attributes need to be unique so you can use it safely to remove only this element without worrying about affecting anything else.

Sign up to request clarification or add additional context in comments.

3 Comments

I have multiple such tr-s <tr class= "numberedListElement> with the same id-s. So i need a way to select the second input from the last td from the tr with class numberedListElement... So it can affect all
As I have mentioned already, your id attributes are required to be unique. You should only have one occurrence of any one id value.
Which input do you want to remove? As @Lix has said, elements can easily be removed by ID ... but your HTML has to be valid - no duplicate IDs.
0

try which is not so generic:

     $("#editor > tr:nth(1) > td:nth(2) > input:nth(1)");

anyways, use last and not last-child

Comments

-1

I can see you have a TR element inside another TR element.. if you remove that, it might work.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.