tags:

views:

60

answers:

3

I have a lot of div boxes with nested div .titles, with a button inside. Is there a way in jQuery to select the parent of the button?

Something like:

$("#button").click(function(){       
       $("this.parent").css({'border-bottom' : 'none'});
       }); 

Or am I going to have to rename all of my title classes to unique classes?

+7  A: 

Try this :

$("#button").click(function(){       
       $(this).parent().css({'border-bottom' : 'none'});
       });

or $(this).parent("div").css({'border-bottom' : 'none'});

c0mrade
+7  A: 

Give this a whirl (inside an event handler for that button):

$(this).parent().css({'border-bottom' : 'none'});
GlenCrawford
@GlenCrawford you got extra " in there
c0mrade
@c0mrade: bug = neutralized
GlenCrawford
@GlenCrawford affirmative :)
c0mrade
Thanks, worked perfectly! Still learning jQuery, best way to do it us by doing!
Kyle Sevenoaks
@Kyle Sevenoaks break a leg, +1 Glen
c0mrade
Thanks :) one day I'll answer a jQuery question :P
Kyle Sevenoaks
very soon hopefully
c0mrade
+1  A: 

jQuery.parent()

$(function(){
  $("div.title a").click(function(){
    $(this).parent().css("background-color", "red");
    return false;
  });
});
Anpher