append value to an element dynamically

append value to an element dynamically

I want to put values into an array dynamically and get the same from a click event and put some text into the element. All this happens on the fly. I am not sure why the following piece of code fails. Everything worked except this line : $(gval[0]).append(" Bro, whats up? ");


Code :

var gval = [];
// Headers to initialize jquery
$(document).click(appendThisHere);

function appendThisHere(e){
gval.push("\"" + e.target.nodeName + "\"");
$(gval[0]).append(" Bro, whats up? ");
}


Any help appreciated !