Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.