0

I am inserting HTML into my webpage and want to change some of the elements with jQuery. The file is being read every second and this is the element that I want to change:

<div id="progress" class="progress-bar progress-bar-info progress-bar-striped" role="progressbar" aria-valuenow="20" aria-valuemin="0" aria-valuemax="100" style="width: 20%">

I tried the following (didn't work):

<script>
function change(){ $("#progress").attr('aria-valuenow', '60'); 
};
change();
</script>

I also tried this (didn't work):

<script>
function change(){ $("#progress").attr('aria-valuenow', '60'); }; change();
</script>

The website is definitely reading properly from the file, and it is probably just the way that I am inserting the code that doesn't make the change.

Help please.

P.S. I am re-reading the file that inputs the HTML with the following AJAX call. Basically it just re-reads the file every second and appends html to a div:

<script>
$(document).ready(function() {
    var filename = "path/to/file/" + fileName;
    console.log(filename);
    setTimeout(functionToLoadFile, 10);
    function functionToLoadFile(){
            $.ajax({
                url: filename,
                cache: false,
                success: function(data) {
                    $('#content').html(data);
                    setTimeout(functionToLoadFile, 1000);
                },
            });
    }
});
</script>

Thanks to everyone who responds <3

4
  • Where's the code that read the file every second? Commented Jun 27, 2015 at 15:21
  • Did you try inserting your JS code in $(document).ready(function() { change(); }); ? Basically it assures you that your code "waits" for the DOM to be loaded before trying to access / modify it : learn.jquery.com/using-jquery-core/document-ready. The change function can be outside. Commented Jun 27, 2015 at 15:30
  • not enough info to provide solution Commented Jun 27, 2015 at 15:37
  • Flo, the page is already loaded and I am making an AJAX call for a file that appends html to it. Fuyushimoya and vinayakj, I edited my first message with the AJAX call. Thank you all for the cooperation. Commented Jun 27, 2015 at 15:49

1 Answer 1

1

Try this jsfiddle

Basically:

$("#progress").progressbar("option", "value", 60);
Sign up to request clarification or add additional context in comments.

3 Comments

Thank you for the suggestion, however I am getting an error 'Uncaught TypeError: $(...).progressbar is not a function' even though it's working on the jsfiddle that you sent :(
He included jQuery UI
Oops, you are absolutely correct. I tried it this way and still no joy, however since it is working for him it should definitely work on my end too. Thank you all very much for the suggestions.

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.