简体   繁体   中英

Set innerhtml of a div echoed by php

I created a div element using php echo

*//some html code*
*<?php echo "<div id = "randomDiv"></div>" ?>
<script>
     document.getElementById("randomDiv").innerHTML = "Hey";
</script>*

but this does not manipulate the innerHTML of the div. Any ideas how to resolve this?

Double quote for div id makes it invalid. Try changing the quote to single quote:

<?php echo "<div id='randomDiv'></div>"; ?>
<script>
     document.getElementById("randomDiv").innerHTML = "Hey";
</script>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM