tags:

views:

4755

answers:

2

I hope this isn't a waste of time, however I have really been trying to figure this on out. Is it my syntax. I simply want to remove the parent div ".number-row" once the link with a class of ".remove-link" is clicked.

Thanks in advance

<script>
$(document).ready(function(){
    $(".remove-link").click(function() {
     $(this).parent(".number-row").hide();
    })
})
</script>

<div class="number-row" >
   <div class="number-column">
         <div class="label-row">
             Select Country:
         </div>
         <div class="input-row">
             <select>
                 <option>1</option>
                 <option>2</option>
             </select>
         </div>
         <div class="label-row">
             Select Toll Free or City:
         </div>
         <div class="input-row">
             <select>
                 <option>1</option>
                 <option>2</option>
             </select>
         </div>
         <div class="label-row">
             Select Your Number:
         </div>
         <div class="input-row">
             <select>
                 <option>1</option>
                 <option>2</option>
             </select>
         </div>
     </div>
   <div class="number-column">
         <div class="label-row">
             Select Country:
         </div>
         <div class="input-row">
             <select>
                 <option>1</option>
                 <option>2</option>
             </select>
         </div>
         <div class="label-row">
             Enter Number to Forward to:
         </div>
         <div class="input-row">
            <input type="text" name="forward_number" id="forward_number" />
         </div>
         <div class="number-row-options">
            <a class="save-link" href="#">Save</a>
            <a class="remove-link" href="#">Remove</a>
         </div>                    
     </div>                    
</div>
+1  A: 

This should do it...

$(document).ready(function(){ 
    $(".remove-link").click(function() { 
     $(this).parent().parent().parent().hide();
    }) 
})

Note that this doesn't remove, which you requested; it simply hides it. You can use remove() instead of hide() to remove it from the DOM.

cLFlaVA
+6  A: 

Try parents() instead of parent():

$(document).ready(function(){
    $(".remove-link").click(function() {
        $(this).parents(".number-row").eq(0).hide();
    })
})
Jason Anderson
I usually do a slice(0, 1) as well to just get the closest matching parent, though with a such specific selector it might not be that important..
svinto
why not just :first?
redsquare
you can use :first or :eq(0)
Ata