Jump to content

Function in <div>


dotkpay

Recommended Posts

Not sure I got what you mean,

 

But here is an example:

 

<html>
<head>
<style type="text/css">
#area1
{
position:absolute;
top:100px;
left:100px;
}
</style>
</head>
<body>
<div>
<script type="text/javascript">
function greet()
{
document.write("Hello, Good morning");
}
</script>

<button onclick="greet()">Click to greet</button>

<div id="area1"></div>

</div>
</body>
</html>

 

Could you please show me how to make the greeting appear inside the div(area1) when I click the button.

Link to comment
https://forums.phpfreaks.com/topic/253658-function-in/#findComment-1300392
Share on other sites

hope this helps

<body>
<div>
<script type="text/javascript">
function greet()
{
var asd = document.getElementById['area1'];
area1.innerHTML = "Hello, Good morning";
}
</script>

<button onclick="greet()">Click to greet</button>

<div id="area1"></div>

</div>
</body>
</html>

Link to comment
https://forums.phpfreaks.com/topic/253658-function-in/#findComment-1300404
Share on other sites

You shouldn't mix your code into your markup. There are frameworks around these days that support unobtrusive JavaScript allowing you to attach events to elements by selecting those elements using CSS selectors.

 

jQuery is probably the most popular of these frameworks, check it out.

Link to comment
https://forums.phpfreaks.com/topic/253658-function-in/#findComment-1300407
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.