I have the following html (fiddle link)
<div class="thumbnail_follow" id="follow_btn-2">
<a class="btn btn-primary" data-method="post" data-remote="true" rel="nofollow">Follow</a>
</div>
upon clicking on the button, I want the button to replace itself with an unfollow button with the html of
<div class="thumbnail_follow" id="follow_btn-2">
<a href="/users/2/unfollow" class="btn btn-danger" data-method="post" data-remote="true" rel="nofollow">Unfollow</a>
</div>
So basically, change the button and the link which it points to
I use jQuery html() like this
$("#follow_btn-2").html('<a class=\"btn btn-danger\" data-method=\"post\" data-remote=\"true\" rel=\"nofollow\">Unfollow<\/a>');
note this is generated via rails ujs from the code
$("div[id='follow_btn-<%= @user.id %>']").html('<%=j link_to "Unfollow", unfollow_user_path(@user), :remote => true, :method => :post , :class=>"btn btn-danger"%>');
the problem, as visible from the jsfiddle, is that once the button is replaced with the red one, it jumps away as if its style got messed up..
I don't understand what is causing the jump and how to fix it.. Is it a css problem or a bad jQuery usage?
here is the fiddle once more
.attr()?!important- it is generally not required. See css-tricks.com/when-using-important-is-the-right-choice