Search code examples
jqueryfadeappendchild

Fade in word with JQuery


I tried looking at the different blogs but still not sure how to set this up. I am trying to convert my original to jQuery and well I am having issues creating a fading effect since I am appending the word and not sure how I need to change my code.

Of course if you need to see my whole js file let me know. Thank you for any help guys

function listWordsUsed(wordUsed) {
    var userTrials = document.getElementById("userGuesses");
    var divisor = document.createElement("div");
    divisor.innerHTML = "<div id=" + wordUsed + ">" + $(this).fadeIn(5000); + "</div>";
    userTrials.appendChild(divisor);
    return;
} //End of function listWordsUsed(wordUsed)

Solution

  • Using full blown jQuery:

    function listWordsUsed(wordUsed) {
        var userTrials = $('#userGuesses');
        var divisor = $("<div><div id=" + wordUsed + "></div></div>");
        divisor.hide().appendTo(userTrials).fadeIn(5000);
        return;
    } //End of function 
    
    listWordsUsed(wordUsed);
    

    If you're trying to append the word guessed, then you should change the code slightly:

    var divisor = $("<div>" + wordUsed + "</div>");
    

    Demo