The $('#stop')
selector can't works because you have no html element with the id stop
when you run it. So you have 2 choices : Use only one listener or use the delegation system of jQuery.
One listener :
$('#start').click(function() {
var $this = $(this),
id = $this.attr('id');
if (id == 'start') {
$this.attr('id', 'stop');
$this.html('Stop!');
} else {
$this.attr('id', 'start');
$this.html('Start!');
}
});
Delegation system :
$(document.body).on('click', "#start", function(){
$(this).attr("id", "stop");
$(this).html("Stop!");
});
$(document.body).on('click', "#stop", function(){
$(this).attr("id", "start");
$(this).html("Start!");
});
Anyway, mplungjan is right. Changing the ID is not a good idea. You should use a CSS class for that.