[Answer]-Dynamically create input elements based on clicked element

1👍

With that structure this should work (heres a fiddle http://jsfiddle.net/uBZRW/2/)

$('.column a').click(function ()
{
    var targetParaphaph = $(this).parent().prev(); // This gets the previous <p>
    var value = targetParaphaph.text();
    targetParaphaph.html("<input type='text' value='"+value+"'/>");
    $(this).addClass('success'); // this results in "button success" class
});

Edit: I edited the original answer with multiple fixes to the code, fiddle contains a working example, if your structure is different you can implement a similar logic using jquery .parent(), .parents([selector]), .next(), .prev(), etc

jQuery DOM Traversing: http://api.jquery.com/category/traversing/

Leave a comment