I´d like to prepend a div with an onClick function via jQuery like that:
var myFirstDivChange = '<div class="myClass" onClick="changemyvariable('4v5');">MyText</div>',
$('#myDiv').prepend(myFirstDivChange);
This is the changemyvariable function:
function changemyvariable (mynewvariable) {
var myoldvariable = mynewvariable
}
It does not work and returns
SyntaxError: syntax error
changemyvariable(
Is there a problem with " or ' ? If i try it like "4v5" it does not work either..
'
within'
. – Daniel A. White Dec 10 '13 at 21:23changemyvariable(\'4v5\')
but really you ought to be binding that event dynamically rather than coding it into the markup. – Michael Berkowski Dec 10 '13 at 21:23.click()
to bind the event rather than hard-coding it. – Michael Berkowski Dec 10 '13 at 21:25