Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

132
Views
Keeping track of which button was pressed?

So I have 2 buttons, when clicked on they lead to the same window. But, I want to be able to keep track of which button was pressed so I can do different things based on that, below is how I have them defined:

<div class = "buttons">
     <button class = "worldBtn" onclick="window.location.href='map/map.html';">WORLD</button>
     <br>
     <button class = "usBtn" onclick="window.location.href='map/map.html';">UNITED STATES</button>
</div>

Is there any way I will be able to achieve that? Thanks!

about 4 years ago · Juan Pablo Isaza
3 answers
Answer question

0

Use a URL query parameter to distinguish them.

<div class = "buttons">
     <button class = "worldBtn" onclick="window.location.href='map/map.html?loc=world';">WORLD</button>
     <br>
     <button class = "usBtn" onclick="window.location.href='map/map.html?loc=us';">UNITED STATES</button>
</div>

Then in map.html the JavaScript can check window.location.search to determine which button was used.

about 4 years ago · Juan Pablo Isaza Report

0

add one same class to button on click using $(this) you get it value attribute. here is a small code snippet

 
$(".btn").click(function(e){
var title=$(this).attr("value");
alert(title);
});
 
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<div class = "buttons">
     <button class = "worldBtn btn" onclick="window.location.href='map/map.html';" value="WORLD">WORLD</button>
     <br>
     <button class = "usBtn btn" onclick="window.location.href='map/map.html';" value="UNITED STATES">UNITED STATES</button>
</div>

about 4 years ago · Juan Pablo Isaza Report

0

You can use the click event to track which button was clicked and act accordingly

HTML

<div class = "buttons">
     <button id="btn1" class = "worldBtn">WORLD</button>
     <br>
     <button id="btn2" class = "usBtn">UNITED STATES</button>
</div>

Javascript using JQuery

$('#btn1').on('click', function(e) {
   e.preventDefault();
   console.log('worldBtn clicked');
   window.location.replace("map/map.html");
})

$('#btn2').on('click', function(e) {
   e.preventDefault();
   console.log('usBtn clicked');
   window.location.replace("map/map.html");
})
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!