1

I am trying to replace some div text automatically using the .html command in Jquery but it's not working for me. This is the code I have so far:

    <div id="test">123</div>

    <script type="text/javascript">

    jQuery(document).ready(function(){

    var refreshId = setInterval(function()

    {

    $('#test').html("test");

    }, 1000);


});

</script>

Could someone tell me what I'm doing wrong please? I have ran tests to make sure Jquery is working and it is, and if I run alert('test'); then that works fine.

Thanks for any help

Edit: I have ran the script in another file on localhost and it works fine - could it be something within the code I'm using already that's stopping it from working? This is baffling me!

8
  • 2
    It works very well: jsfiddle.net/fkling/ZKTKn Commented Jul 5, 2011 at 11:06
  • Are you sure the interval is called? Commented Jul 5, 2011 at 11:07
  • 1
    by the way, are you sure you want to use setInterval? Maybe setTimeout? Commented Jul 5, 2011 at 11:07
  • What tests did you run? Have you loaded another library? Please post more code. Commented Jul 5, 2011 at 11:10
  • 1
    The script works fine inside another file...is there something that could potentially be blocking this from working? Commented Jul 5, 2011 at 11:18

2 Answers 2

2

When I have problems like this it's usually due to some javascript/jquery prior to this part which is incorrect.

If you can, try proofing or commenting out some other parts of your code to see if you can make it work.

Sign up to request clarification or add additional context in comments.

1 Comment

I found the problem :) I'm trying to do it in a wordpress theme and the theme calls different .php files and I had to include Jquery in the seperate PHP file as well. Not sure why alert() was working though, and the Jquery tests I got from here jquery-howto.blogspot.com/2009/03/…
0

In your full page code, is it possible that you have one more control with the same id? If so, jQuery can select it instead of your div.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.