JamesB JamesB - 3 months ago 8
jQuery Question

Jquery text returning weird values

My code is gerating strange output, I just want to get value of an element, but it returns me some kind of code. Sorry if it was a fool question, I am starting in JavaScript:



function clicarBotao(id){
var text=$("#"+id).html;
alert(text);
}
</script>

<body>
...
<ul>
<li id="1" class="botaoMenu" onclick="clicarBotao(1)">Menu 1</li>
</ul>
...
</body>


Alert returns:

function ( value ) {
return jQuery.access( this, function( value ) {
var elem = this[0] || {},
i = 0,
l = this.length;

if ( value === undefined ) {
return elem.nodeType === 1 ?
elem.innerHTML.replace( rinlinejQuery, "" ) :
undefined;
}


code does not end here ...

Answer

You need html(), not html. It is printing the function definition.

Comments