I have the jQuery function below which alters the CSS on hover of a p element.
$("p").hover (
function() {$(this).addClass("choice"); } ,
function() { $(this).removeClass("choice");} );
The problem is that it will not function for the innerHTML of a div written with .html() or .append(), like so
$('#div').html('<p>content that needs to highlight on hover</p>');
Even if I try to insert the function itself to that innerHTML like so
$('#div').append('<script type="text/javscript">$("p").hover ( function() {$(this).addClass("choice"); } , function() { $(this).removeClass("choice");} );<'+'/script>');
it will still not function for the HTML content of that div.
What am I missing here? Thanks, any help would be much appreciated.
"#div"in your real code because that could very easily confuse someone. Either use"div"or"#usefulname". Usingid="div"is a recipe for confusion.