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'.changemyvariable(\'4v5\')but really you ought to be binding that event dynamically rather than coding it into the markup..click()to bind the event rather than hard-coding it.