Title: Execute function in elements by class not running
Tags: jquery;class;onclick
Question: I can't run this code, Jquery is okay, I done it inside $(document) because of some advice read here in the site, that I forgot the link. The problem is that it does not run.. Sorry if it's fool question, I am not a front-end programmer. -Please ignore on onclick="adicionaItemNoMenu();return false;" inside button
<html&gt;
<head&gt;
<script src="http://code.jquery.com/jquery-1.9.1.js"&gt;</script&gt;
</head&gt;
<body&gt;
<script type="text/javascript"&gt;
$(function() {});
$(document).ready(function() {
$('.botaoMenu').click(function() {
alert("Oi");
});
});
</script&gt;
<table&gt;
<tbody&gt;
<tr&gt;
<td id="menu"&gt;
<ul&gt;
<li id="1" class="botaoMenu"&gt;Menu 1</li&gt;
</ul&gt;
</td&gt;
</tr&gt;
</tbody&gt;
</table&gt;
</body&gt;
</html&gt;
Whole Code with not mainly codes:
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%&gt;
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"&gt;
<html&gt;
<head&gt;
<script src="http://code.jquery.com/jquery-1.9.1.js"&gt;</script&gt;
<script type="text/javascript"&gt;
$(document).ready(function(){
$('.botaoMenu').click(function() {
// $(this.id).html($(this.id).html+'<ul&gt;<li&gt;<input type="submit" value="Novo Item"&gt;</li&gt;</ul&gt;');
alert("Oi");
});
var id=1;
var menuPrincipal = [];
function itemMenu(idItem,descricao) {
this.idItem=idItem;
this.descricao = descricao;
this.posicao = menuPrincipal.length+1;
this.link = "";
this.itensMenuInterno=[];
function adicionaBotao()
{
//$("#menu").html("tarefa okay");
$("#menu").after('<li&gt;<a id="'+id+'" onClick="return adicionaItem('+id+');"&gt;Menu '+id+'</a&gt;</li&gt;');
id++;
function adicionaItemNoMenu()
/*
(1)Cria Novo Objeto Item do Menu na lista da de objetos itens do menu,
em seguida atualiza o menu
*/
var instanciaItemMenu=new itemMenu(id,'hi');
menuPrincipal.push(new itemMenu(id,'Menu '+id));
this.id=id+1;
atualizaMenuControlador();
function atualizaMenuControlador()
/*
(2)Insere as atualizações processadas pela função atualiza
menu enviando o array de objetos de menu
*/
$("#menu").html(atualizaMenuComClasse(menuPrincipal,"botaoMenu"));
function atualizaMenu(arrayDeListas)
return atualizaMenuComClasse(arrayDeListas,"");
function atualizaMenuComClasse(arrayDeListas,classe)
/*
(2.1) Processa objetos do array de objetos de menu (botões do menu) retornando-os em forma
de Html para serem inseridos no menu.
*/
var textoFinalDoMenu="";
if(classe.length==0)
textoFinalDoMenu=textoFinalDoMenu+'<ul&gt;';
else
textoFinalDoMenu=textoFinalDoMenu+'<ul&gt;';
for ( var i = 0 ; i < arrayDeListas.length ; i++ ) {
textoFinalDoMenu=textoFinalDoMenu+'<li class='+classe+' id='+arrayDeListas[i].idItem+'&gt;';
textoFinalDoMenu=textoFinalDoMenu+arrayDeListas[i].descricao;
if(arrayDeListas[i].itensMenuInterno&gt;0){
textoFinalDoMenu=textoFinalDoMenu+atualizaMenu(arrayDeListas);
}
textoFinalDoMenu=textoFinalDoMenu+'</li&gt;';
}
textoFinalDoMenu=textoFinalDoMenu+'</ul&gt;';
return textoFinalDoMenu;
</script&gt;
</head&gt;
<body&gt;
<table&gt;
<tr&gt;
<td id="menu"&gt;</td&gt;
<td id="botao"&gt;
<form&gt;
<button value="Adiciona" onclick="adicionaItemNoMenu();return false;"&gt;Adiciona1</button&gt;
</form&gt;
</td&gt;
</tr&gt;
</table&gt;
</body&gt;
</html&gt;
Comment: I do not use console, there is an IDE to javascript? I programming it in a JSP page in Eclipse. Look: this Menu 1 is an generated Jquery code (I am using firebug to see the generated HTML code) , can it be the source of problem, does this function does not work with the non existing primary code?

Comment: It is working Check [This](http://jsfiddle.net/cse_tushar/9agvv/). Do you get any error on console where you are  testing it ?

Comment: `$(function (){` is the equiv of `$(document).ready(function() {`



{'source': 'StackExchangeDataset', 'subset': 'stackoverflow.com', 'metadata': {'AnswerCount': 0, 'CommentCount': 3, 'ContentLicense': 'CC BY-SA 3.0', 'CreationDate': '2013:00:10/28/13', 'FavoriteCount': None, 'PostTypeId': 1, 'Tags': '<jquery><class><onclick>', 'Title': 'Execute function in elements by class not running', 'ViewCount': 66, 'id': 19626035, 'user_AboutMe': "<p><em>Brazilian. Actually have Analysis and Development Technological Degree, actually studying System Engineering Bachelor and Lato Sensu Software Engineering. Like to program in java and Unity3D, and I'm a musician by hobby</em></p>\n", 'user_AccountId': 1810821.0, 'user_DisplayName': 'JamesB', 'user_Reputation': 501.0, 'user_Views': 100.0, 'user_id': 1646928.0}}