// Change Link Destination
document.getElementById("link").href
= "https://google.com";
// Swap Image Source
document.getElementById("img").src
= "img2.jpg";
This demonstrates Attribute Manipulation. You can programmatically redirect users or update graphics without a page refresh.
<ul id="list">
<li>Item 1</li>
</ul>
<script>
document.getElementById("list").innerHTML
+= "<li>Item 2</li>";
</script>
Using innerHTML with the += operator allows you to append new HTML tags. This is how "Add to List" features are built.
<button onclick="hello()">Click</button>
<script>
function hello(){
alert("Hello from Point Pikker!");
}
</script>
Functions allow you to group code. By linking a function to a button's onclick event, you control exactly when that logic runs.
<form onsubmit="submitForm()">
<input type="text">
<button>Submit</button>
</form>
<script>
function submitForm(){
alert("Form data sent!");
}
</script>
The onsubmit event is specific to forms. It captures the moment a user finishes entering data, allowing you to validate it before it leaves the page.
<input id="userName">
<script>
function getName(){
let val = document.getElementById("userName").value;
alert("Hello, " + val);
}
</script>
The .value property is unique to inputs. It allows JavaScript to "read" what the user has typed, which is the foundation of search bars and user profiles.