1
I’m creating an extension, my first extension for Google Chrome, the extension consists of changing elements of any page and change things, but wanted to put a function to a button via onclick
, but it doesn’t work!
Suppose the site has the following structure HTML:
<button class="one" onclick="funcaoOriginal();">Teste</button>
In the archive js
of the extension have the following:
function minhaFuncao(){
alert('teste');
}
$('.one').attr('onclick','minhaFuncao()');
but it doesn’t work! , if so:
$('.one').attr('onclick','alert(\'teste\')');
It works, but I want to put things like $.each
and $.cookie
inside a function and call it by clicking on the button of the site.
How would I do that?
Where’s that
minhaFuncao()
code? is in the global scope or within another function such as.ready()
?– Sergio
And why not use
$('.one').on('click', minhaFuncao);
?– Sergio
Within the
.ready()
@Sergio, I tried to$('.one').click(function(){ //codigo });
and it worked! had not thought before. thank you very much.– Cassiano José