JQuery Delegate and using traveral options in function

Posted by Brian on Stack Overflow See other posts from Stack Overflow or by Brian
Published on 2010-05-06T18:55:18Z Indexed on 2010/05/06 18:58 UTC
Read the original article Hit count: 233

Filed under:
|
|
|

I am having trouble figuring out how to use the JQuery delegate function to do what I require. Basically, I need to allow users to add Panels (i.e. divs) to a form dynamically by selecting a button. Then when a user clicks a button within a given Panel, I want to be able to to something to that Panel (like change the color in this example). Unfortunately, it seems that references to the JQuery traversing functions don't work in this instance. Can anybody explain how to achieve this effect? Is there anyway to bind a different delegate to the each panel as its added.

$('.addPanels').delegate('*', 'click', function() {
$(this).parent.css('background-color', 'black');
$('.placeholder').append('Add item');
});

<div class="addPanels">  
    <div class="panel">   
        <a href="#" class="addLink">Add item</a> text</div>  
       <div class="placeholder"/>  
    </div>  
</div>  

© Stack Overflow or respective owner

Related posts about jQuery

Related posts about delegate