Half of a day have been looking for this elegant solution.
Thanks Peter, your genius!
Thanks to Pete Higgings as well.
On May 1, 4:38 pm, Peter Edwards wrote:
> Hi Roman,
>
> You need to copy the reference to your link to a variable like this:
>
> jQuery('#yt1').click(function(){
> $(this).replaceWith("Approving...");
> var aObj = $(this);
> jQuery.ajax({
> 'type':'POST',
> 'data':'id=205',
> 'dataType':'text',
> 'success':function(msg){
> alert(aObj.attr("id"));
> },
> 'url':'/approve/article',
> 'cache':false
> });
> return false;
>
> });
>
> on 01/05/2009 11:48 phpdevmd said::
>
> > Hello, I have the following jquery ajax request:
>
> >
> >
> >
> >
> >
> > Approve
> >
> > /*<![CDATA[*/
> > jQuery(document).ready(function() {
> > jQuery('#yt1').click(function(){
> > $(this).replaceWith("<i>Approving...</i>");
> > jQuery.ajax({
> > 'type':'POST',
> > 'data':'id=205',
> > 'dataType':'text',
> > 'success':function(msg){
> > alert($(this).attr("id"));
> > },
> > 'url':'/approve/article',
> > 'cache':false
> > });
> > return false;
> > });
> > });
> > /*]]>*/
> >
> >
> >
>
> > First replaceWith working fine, link changes to 'Approving', but alert
> > saying 'undefined' instead of 'yt1'...
> > Any ideas acessing this link in a script where I don't know exactly
> > what id does this link have?
> > I know that alert($("#yt1").attr("id")); would work, but 'yt1' is auto-
> > generated by my framework, so I need to access it without $("#_id_")
> > but using 'this' or any other appropriate method.
>
> > Thanks in advance.
> > Roman