[jQuery] $.ajaxStart bind on a unique element

2008-05-02 Thread LostCore

Hi!

I have this:

-
$(".submit_textarea").livequery("click", function(e){
e.preventDefault();
if($(this).attr("href") == "#save")
{
var savencancel = $(this).parent();
var textarea = $
(this).parents(".imagencap").children("textarea");
var caption = textarea.val();
var idimage = textarea.attr("id");
idimage_array = idimage.split("-");
var maindiv = $(this).parents(".imagencap");

$.ajax({
type: "POST",
url: "galleries.php",
data: "a=jchange-
caption&id="+idimage_array[1]+"&caption="+caption,
success: function(data){
textarea.hide("slow", function(){
$(this).remove();
});
savencancel.remove();
maindiv.append(""+data+"");
}
});
}

[ect...]
--

and i would to show an image (the loader) only attached to the element
that have sended the ajax request (which have a unique id).

If i do

---
$(".imagencap")
.ajaxStart(function(){
 
})
--

It will binds to all the element on the page...

Any help?

Thanks!


[jQuery] Re: How to bind to multiple elements

2008-04-27 Thread LostCore

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 :)


[jQuery] How to bind to multiple elements

2008-04-27 Thread LostCore

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 = ""+myCaption+"";
var buttons = "[SAVE] [CANCEL]";
myP.hide();
myP.before(""+textarea+""+buttons);
});
[/code]

... That works!. But only for the first occurrence!

Where is the problem?

Thanks :)