Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...


How to have an element invoke a javascript on selection, instead of going to a new url?



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

Post New Answer

More JavaScript Interview Questions

What is the difference between innerhtml & innertext?

1 Answers  


What is the scope of variables in JavaScript?

1 Answers  


What are all the types of Pop up boxes available in JavaScript?

1 Answers  


What is the main difference between Map collections and other collections such as Set.

1 Answers  


How do I turn on javascript?

1 Answers  


What is escape & unescape String functions in JavaScript?

1 Answers  


Which is best for front end?

1 Answers  


Explain a story about javascript performance problems?

1 Answers  


what is function of stdio.h

1 Answers   TCS,


About document.getElementID? Explain giving one example. This was asked by a interviewer when i said that i know some JavaScript.

2 Answers   TCS,


Why do we need to declare variables?

1 Answers  


What is the potential disadvantage of using a sticky session?

1 Answers  


Categories