Questions tagged [onclick]

An event which occurs when user clicked an object. It is a combination of two events, that is, "onmousedown" and "onmouseup".

Tag Usage

This tag is used frequently on questions surrounding Javascript event handling. It is worth noting that virtually every conceivable question has been asked on this topic so before you hit that post your question button, have you had a quick look to see if your question has already been covered?

14616 questions
1449
votes
31 answers

Trigger a button click with JavaScript on the Enter key in a text box

I have one text input and one button (see below). How can I use JavaScript to trigger the button's click event when the Enter key is pressed inside the text box? There is already a different submit button on my current page, so I can't simply make…
kdenney
  • 18,343
  • 4
  • 31
  • 27
969
votes
21 answers

addEventListener vs onclick

What's the difference between addEventListener and onclick? var h = document.getElementById("a"); h.onclick = dothing1; h.addEventListener("click", dothing2); The code above resides together in a separate .js file, and they both work perfectly.
William Sham
  • 12,849
  • 11
  • 50
  • 67
672
votes
49 answers

RecyclerView onClick

Has anyone using RecyclerView found a way to set an onClickListener to items in the RecyclerView? I thought of setting a listener to each of the layouts for each item but that seems a little too much hassle I'm sure there is a way for the…
CurtJRees
  • 6,738
  • 3
  • 14
  • 9
492
votes
14 answers

Can I have an onclick effect in CSS?

I have an image element that I want to change on click. This works: #btnLeft:hover { width: 70px; height: 74px; } But what I need is: #btnLeft:onclick { width: 70px; height: 74px; } But, it doesn't work,…
Alegro
  • 7,534
  • 17
  • 53
  • 74
449
votes
17 answers

How exactly does the android:onClick XML attribute differ from setOnClickListener?

From that I've read you can assign a onClick handler to a button in two ways. Using the android:onClick XML attribute where you just use the name of a public method with the signaturevoid name(View v) or by using the setOnClickListener method where…
emitrax
  • 4,565
  • 3
  • 18
  • 8
328
votes
11 answers

Calling a parent window function from an iframe

I want to call a parent window JavaScript function from an iframe.
Arjun Singh
  • 3,291
  • 2
  • 16
  • 6
326
votes
14 answers

Onclick javascript to make browser go back to previous page?

Is there a function I can attach as a click event of a button to make the browser go back to previous page?
Doc Holiday
  • 9,928
  • 32
  • 98
  • 151
326
votes
13 answers

React onClick function fires on render

I pass 2 values to a child component: List of objects to display delete function. I use a .map() function to display my list of objects(like in the example given in react tutorial page), but the button in that component fires the onClick…
Stralos
  • 4,895
  • 4
  • 22
  • 40
313
votes
15 answers

How to call multiple JavaScript functions in onclick event?

Is there any way to use the onclick html attribute to call more than one JavaScript function?
Qcom
  • 18,263
  • 29
  • 87
  • 113
282
votes
12 answers

How to have click event ONLY fire on parent DIV, not children?

I have a DIV with a classed foobar, and a few DIVs inside that DIV that are unclassed, but I suppose they are inheriting the foobar class: $('.foobar').on('click', function() { /*...do stuff...*/ }); I want that to fire off only when clicking…
CaptSaltyJack
  • 15,283
  • 17
  • 70
  • 99
245
votes
15 answers

Show/hide 'div' using JavaScript

For a website I'm doing, I want to load one div, and hide another, then have two buttons that will toggle views between the div using JavaScript. This is my current code function replaceContentInContainer(target, source) { …
Jake Ols
  • 2,792
  • 3
  • 18
  • 29
233
votes
10 answers

Remove an onclick listener

I have an object where the text cycles and displays status messages. When the messages change, I want the click event of the object to change to take you to the activity that the message is relating to. So, I have a TextView mTitleView and I'm…
Josh
  • 16,286
  • 25
  • 113
  • 158
233
votes
7 answers

How to simulate a button click using code?

How can I trigger a button click event using code in Android? I want to trigger the button click programmatically when some other event occurs. Same Problem I am Facing public void onDateSelectedButtonClick(View v){ /*Something Alarm…
sam
  • 2,333
  • 2
  • 14
  • 5
218
votes
10 answers

How can I prevent event bubbling in nested React components on click?

Here's a basic component. Both the
    and
  • have onClick functions. I want only the onClick on the
  • to fire, not the
      . How can I achieve this? I've played around with e.preventDefault(), e.stopPropagation(), to no avail. class List…
dmwong2268
  • 3,315
  • 3
  • 19
  • 20
216
votes
8 answers

How to click or tap on a TextView text

I know this is so easy (doh...) but I am looking for a way to run a method on tapping or clicking a TextView line of text in an Android App. I keep thinking about button listeners and anonymous method listener calls, but it just does not seem to…
Droid
  • 2,467
  • 2
  • 17
  • 9
1
2 3
99 100