Thanks for all the advices! It was a very newbie error :P
Can i ask another little question?
Starts with this code (a new version of what i posted early)
$(".imagencap").bind("click", function(){
if($(this).children().is("textarea")){ return; } //return if
textarea is already created
var myP = $(this).find("p");
var myCaption = myP.text();
var myId = myP.attr("id");
//alert(myId+": "+myCaption);
var textarea = ""+myCaption
+"";
var buttons = "[SAVE]
[CANCEL]";
myP.hide();
myP.before(""+textarea+""+buttons);
$(this).find("span").find("a").bind("click", function(e){
e.preventDefault();
if($(this).attr("href") == "#save"){
//alert("salvo!");
}
if($(this).attr("href") == "#cancel"){
//alert("cancello!");
$(this).parent().hide("slow");
$
(this).parents(".imagencap").children("textarea").hide("slow");
//$(this).parents(".imagencap").children("textarea").remove();
$(this).parents(".imagencap").find("p").show();
}
});
});
Well, this code put a "SAVE" and a "CANCEL" links at the bottom of the
textarea (for each images). When i click "CANCEL" i would to do that
textarea and button hides and the came back.
In code i've posted, when i click on these links the click event
propagate to the imagencaption class, so:
- if i hide the textarea, i can't do any change anymore (the check at
the first line returns true).
- if i remove the textarea, a new textarea appears (because the check
at the first line fails).
Any idea? Thanks!
On 27 Apr, 19:13, steve_f <[EMAIL PROTECTED]> wrote:
> Do you have multiple divs with the same id of 'images'?. if so you
> need to start using class name selectors, then you can iterate all the
> divs with that clas name e.g
> $(".images").each
>
> On Apr 27, 11:25 am, LostCore <[EMAIL PROTECTED]> wrote:
>
> > Hi!
>
> > Well, i'll quickly describe my problem.
>
> > In a page, i've multiple occurrence of:
>
> > [code]
> >
> >
> >
> >
> > caption_text
> >
> >
> >
> > [/code]
>
> > I would do, that when i click on a "caption_text", the relative
> > paragraph tag hide, and a textarea appears, with the text of the .
>
> > Then, i've scripted this:
>
> > [code]
> > $("#images").find("#imagencap")
> > .click(function(e){
>
> > if($(this).children().is("textarea")){ return; }
>
> > var myP = $(this).find("p");
> > var myCaption = myP.text();
> > var myId = myP.attr("id");
>
> > var textarea = " > id="+myId+">"+myCaption+"";
> > var buttons = "[SAVE] [ > href='#'>CANCEL]";
> > myP.hide();
> > myP.before(""+textarea+""+buttons);
> > });
> > [/code]
>
> > ... That works!. But only for the first occurrence!
>
> > Where is the problem?
>
> > Thanks :)