I have a jQuery function that I want to create with basic javascript (Vanilla) and am having troubles.
<html>
<head>
<title></title>
<style>#cube1{margin-top:35px;width:305px;height:255px;border:1px solid;}</style>
<script src='http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js'></script>
<script>
function create(){
var ad = "<scr"+"ipt type='text/javascript'>";
ad += "alert('boom');";
ad += "</scr"+"ipt>";
$('#cube1').html(ad);
}
</script>
</head>
<body>
<div id='cube1' onclick='create()'>Create</div>
</body>
</html>
I want to remove jquery.
I want to create a new javascript function that I can pass the <div/>
#cube1
and the string variable ad
.
The function will insert the string content into the <div/>
and/or run the script - basically it needs to do the same thing jQuery's html()
function does.
This does not work:
document.getElementById( 'cube1' ).innerHTML = ad;
I need it to run the script (the alert).
Any help is greatly appreciated!