Hi guys,

I change my code from Javascript to jQuery and I believe I have everything allright, but my jQuery is not showing the value. Can you help me with it? I am adding the important snippets but if you need all my code here is it Click Here.

Thank you.

My original Javascript

    function guessesUsed(attemptsTaken) {
        var numGuessesLeft = document.getElementById("userAttempts");
        numGuessesLeft.innerHTML = attemptsTaken;
    }

HTML (Older version)
<div>You have guessed: <span id="userAttempts"></span> times</div>

jQuery version

        function guessesUsed(attemptsTaken) {
            var numGuessesLeft = $('#userAttempts').val();
            numGuessesLeft.innerHTML = attemptsTaken;
        } //End of function guessesUsed(attemptsTaken)

HTML New Version
<p id="guessesUsed">You have guessed: <span id="userAttempts"></span> times out six(6) chances.</p>
CSS for the jQuery version

.guessesLeft {
    font-weight:bold;
    color:#C00;
}

Recommended Answers

All 4 Replies

Hi,

.val() is for form values. you need to use .text()

I did do that before but it was not appearing either. Code is here if you want to see. Click Here

I used your suggestion and now code is running smooth again. Thanks. I am not sure why my fucntion became obsolete but this does makes the code simpler.

Thank you Paul.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.