SSK
SSK

Reputation: 285

Jquery AJAX on A href

I am working on the Jquery A href (used as Button) with button name Install. I've wrote the code for the calling Jquery AJAX file , Ajax file name is update.php.

Once ajax successfully executed , I'm changing a href label using.

$(.install-blue).text('Stop Installing');

Now , I am trying to call updateStop.php. When i click on the Stop Installing (a href). Issue is both are sharing same class name, so that it calling update.php

Is there any unique way to execute this operation ?

Upvotes: 0

Views: 102

Answers (4)

Think Different
Think Different

Reputation: 2815

I am not sure if this example is what you want to do.

$(document).ready(function(){
$('.selector').click(function(e){
    e.preventDefault();
    if($(this).text() == 'Stop Installing'){
        //DO STOP ISTALLING STUFF
    }else{
        //DO INSTALL STUFF
        $(this).text('Stop Installing');
    }    
});

});

Upvotes: 0

Shijin TR
Shijin TR

Reputation: 7756

Fiddle

HTML

 <input type="button" href="update.php" value="Install" class="install-blue" />

jQuery

$('.install-blue').click(function(){
   var url=$(this).attr('href');
   alert(url); ///call this ajax url
   $(this).val('Stop Installing'); // add this on ajax success
   $(this).attr('href','updateStop.php'); // add this on ajax success
});

Upvotes: 0

Yasser Shaikh
Yasser Shaikh

Reputation: 47774

You could use HTML 5 data attribute to save the state like for example : jsfiddle

Html

<a class="install-blue" data-state="stopped">Start Installing</a>
<div id="msg">   
</div>

Jquery

$(document).ready(function(){
    $(".install-blue").click(function(){
        if($(".install-blue").data("state") == "stopped"){
            $(".install-blue").text("Stop Installing");     
            $(".install-blue").data("state", "started");  
        }
        else{
            $(".install-blue").text("Start Installing");
            $(".install-blue").data("state", "stopped");  
        }        
    });
});

Upvotes: 1

Astrid
Astrid

Reputation: 1312

Use:

$('.install-blue').addClass('fistClass');

When the user clicks on install.

Then use:

$('.firstClass').text('Stop Installing');

When the user click on stop installing.

Upvotes: 1

Related Questions