How to have an element invoke a javascript on selection, instead of going to a new url?
Answer / Yogendra Pratap Singh
To make an HTML element invoke a JavaScript function on selection without navigating to a new URL, you can use event listeners such as 'click' or 'change'. Here is a simple example using the 'click' event:
```html
<button id='myButton'>Click me</button>
<script>
document.getElementById('myButton').addEventListener('click', function() {
// Your JavaScript code here
console.log('Button clicked!');
});
</script>
| Is This Answer Correct ? | 0 Yes | 0 No |
What is the difference between innerhtml & innertext?
What is the scope of variables in JavaScript?
What are all the types of Pop up boxes available in JavaScript?
What is the main difference between Map collections and other collections such as Set.
How do I turn on javascript?
What is escape & unescape String functions in JavaScript?
Which is best for front end?
Explain a story about javascript performance problems?
what is function of stdio.h
About document.getElementID? Explain giving one example. This was asked by a interviewer when i said that i know some JavaScript.
Why do we need to declare variables?
What is the potential disadvantage of using a sticky session?