First I verify if the text of the element is "ocultar menu", if it's true, I change the text and add hide Class to some others elements. My intention is that the function breaks there, and see the value of text only in the start of the event, and no when I change it inside the function. But when I click once, it appears hide, very fast in the console of the browser, it's like the functions checks the value and continue to check and pass in the if and in the else part of the code. I used StopPropagation() but doesn't works and I've tried to change the on event to click and not worked too. Need Help, thanks.
var $position = $("#ocult-menu").position();
$("#ocult-menu").on("click",function(){
var $text = $(this).find('p').text();
if ($text == "ocultar menu"){
$(".info").addClass("hide");
$(".photo").addClass("hide");
$(".map").addClass("hide");
$(".similar").addClass("hide");
$(".share").addClass("hide");
$("#menu-single").offset({left: $position.left});
$(".exibir").css("background-position","-1px 430px");
$(this).find('p').text("exibir menu");
}
else if( $text == "exibir menu"){
$(".info").removeClass("hide");
$(".photo").removeClass("hide");
$(".map").removeClass("hide");
$(".similar").removeClass("hide");
$(".share").removeClass("hide");
$("#menu-single").offset({left: $position.left});
$(this).find('p').text("ocultar menu");
}
});
$(this).find('p').text()finds all the text of all<p>s#ocult-menu? Is it anathat is reloading the page? It would help if you created a fiddle that demonstrates the issue.