views:

208

answers:

4

i have an issue.

the code is this:

$("#button").click(function(event){
   $("#threads").html("hi");
});

when i click the button, the text "hi" is just shown in 1 sec. then it disappear. i want it to always be shown after i have clicked. how can i do this?

A: 

Your problem is that you have a timeout or interval that is running every 1000 milliseconds, clearing the HTML of #threads. Either it's running as a timeout (setTimeout) from another $("#button").click() or an interval (setInterval) defined somewhere else. I'm just guessing 1000 milliseconds because you said 1 second and I don't know if you mean for a moment instead.

Eli Grey
i mean for a moment. when i just type $("#threads").html("hi"); it works just fine...i think it has something to do with the click function?
never_had_a_name
We'd have to probably see more of the code to understand your problem better.
apphacker
+4  A: 

The problem might be that your button is inside a form with no action, thus submitting the form back to the page - and reverting your change. Or that button is a link with an empty href.

Add return false; to the end of your click-function to stop the default action.

Magnar
+21  A: 

Try this:

$("#button").click(function(event){
   event.preventDefault();
   $("#threads").html("hi");
});

My guess is button is an [a href] tag or in a form which is causing the page to refresh.

PetersenDidIt
A: 

found the problem. it is a link im clicking on so i have to use preventDefault to disable it or it will redirect to itself and refresh the page=) TOOK ME ONE HOUR TO FIGURE IT OUT!!!!!!!!!!!! GRRRRRRR

never_had_a_name
You may "accept" petersendidit's answer so he gets his karma points :)
Wimmer