user974802
user974802

Reputation: 3457

How to remove an Element present inside nested div

<div id="myordersdiv" style="display: block;">
   <ul>
      <li class="myorderhead active">
         <h5>
            My Orders
            <i class="myorderhead22">2</i>
         </h5>
      </li>
      <div id="ordersdiv">
         <div id="addtoordersdiv53">
         </div>
         <div id="addtoordersdiv54">
         </div>
         </div>
   </ul>
   <div class="confirmorder-row">
      <a id="ordersconfirm" hrer="#" class="btn btn-confirmorder">confirm order</a>
   </div>
</div>

The above is the HTML content of my website

On Uncheck of a Checkbox , i need to remove addtoordersdiv54

Inside a checkbox Listener , i have this code

var id_attr_val = 54 ;
   $("#myordersdiv addtoordersdiv"+id_attr_val).remove;

But its not removing that element , could anybody please help .

Upvotes: 1

Views: 748

Answers (1)

adeneo
adeneo

Reputation: 318222

ID's are unique, doesn't matter if it's nested, just target the unique indentifier.

var id_attr_val = 54 ;
$("#addtoordersdiv" + id_attr_val).remove();

The issue with your code is missing the hash in front of the second ID, and not executing the remove function

$("#myordersdiv #addtoordersdiv" + id_attr_val).remove();

But again, targeting elements with two ID's make no sense, as an ID is unique !

Upvotes: 3

Related Questions