onclick

Provide onclick dynamically and avoid duplicate event calling

余生颓废 提交于 2021-01-28 19:11:38
问题 I try to add an item, just like this sample: https://codepen.io/Gobi_Ilai/pen/LLQdqJ var addToMenu = function () { var newName = $("#addInputName").val(); var newSlug = $("#addInputSlug").val(); var newId = 'new-' + newIdCount; nestableList.append( '<li class="dd-item" ' + 'data-id="' + newId + '" ' + 'data-name="' + newName + '" ' + 'data-slug="' + newSlug + '" ' + 'data-new="1" ' + 'data-deleted="0">' + '<div class="dd-handle">' + newName + '</div> ' + '<span class="button-delete btn btn

How to return an attribute of clicked element in react?

蓝咒 提交于 2021-01-28 14:35:43
问题 I was wondering if there is a simple way to get an attribute of clicked element in React.js : function App () { return ( <button title={'foo'} onClick={myFunction(this)} > click me </button> ) } function myFunction(e) { alert(e.getAttribute('title')); } Right now I'm getting: TypeError: can't access property "getAttribute", e is undefined . I need it inside a function for pass the attribute into another (working) function later on. 回答1: You can access the title via currentTarget try this:

Leaflet OnClick data not dynamically

孤街醉人 提交于 2021-01-28 13:18:06
问题 I have e problem when click marker on my map leaflet and modal show only last data, not dynamically. //Array var koordinat = [ {id: 1, nama: 'Unesa', lat: -7.313047, lang: 112.727151}, {id: 2, nama: 'Coffe Warsalam', lat: -7.310355, lang: 112.732151}, {id: 3, nama: 'Kejaksaan', lat: -7.313824, lang: 112.733235}, ]; //var sikat = []; for(var i = 0; i < koordinat.length; i++) { sikat = new L.Marker(new L.latLng(parseFloat([koordinat[i].lat]), parseFloat([koordinat[i].lang]))).addTo(mymap);

Trigger child element's onclick event, but not parent's

妖精的绣舞 提交于 2021-01-27 15:41:30
问题 I've got some nested elements, each with an onclick event. In most cases, I want both events to fire when the user clicks the child (both parent and child events are triggered - default behavior). However, there is at least one case where I want to trigger the child's onclick event (from javascript, not a user's click), but not the parent's. How can I prevent this from triggering the parent event? What I was is: User clicks A: A's onclick fires. User clicks B: B's onclick fires, A's onclick

How to clear datalist input on click?

戏子无情 提交于 2021-01-27 12:53:38
问题 I have this datalist inside a Lit-Element web component: <input list="cars" name="car" placeholder = "Type car name"> <datalist id="cars"> <option value="Jeep"> <option value="Lamborghini"> <option value="Ferrari"> <option value="Fiat 500"> <option value="Gran Torino"> </datalist> If I select one of these options from the list, and then I click again on input field, I can't see the list of option but only the selected one. If I want to see all the options I have to manually delete with the

Multiple function call on html onclick [duplicate]

会有一股神秘感。 提交于 2021-01-27 04:36:48
问题 This question already has answers here : passing parameter to javascript onclick function (3 answers) Closed 6 years ago . Is there any possibilities to use the onclick HTML attribute to call more than one jQuery functions onclick="$('#editParentDetailsViews').removeClass('tab selected');$('#editStudentDetailsPopupPnl').hide(); return false;" Here, the first function work properly and the 2nd function not working. 回答1: I suggest you these ways: 1- addEventListener : document.getElementById(

Javascript - change paragraph Text on Each Button Click

北城余情 提交于 2021-01-21 12:28:35
问题 I am trying to create 3 buttons, and using javascript, If button 1 is clicked then it changes the "Click a button" text to "You pressed Button 1" Same for Button 2 and 3! And if Button 3 is pressed, the text colour changes to GREEN However, I can't seem to get it to work! Any help would be appreciated Here is my Current Code: <!DOCTYPE html> <html> <head> <title>Button</title> </head> <body> <script type="text/javascript"> function changeText() { var b1 = document.getElementById('b1'); var b2

Slow down onclick window.scrollBy

前提是你 提交于 2021-01-07 07:50:43
问题 I am looking the code for making JavaScript window.scrollBy slower, but I haven't found anything. Could some one please advise me how to animate this type of JavaScript scrolling. And no this link doesn't help me Cross browser JavaScript (not jQuery...) scroll to top animation Here is JSFiddle <a onclick="window.scrollBy(0, 300)">Make me slower</a> 回答1: Not sure this is the best way to do that but it works fine, is nice and clear: function scrollByRate(y, rate) { //calculate the scroll height

click event as props in Vue.js

谁都会走 提交于 2021-01-01 07:33:15
问题 I created a dynamic overlay component with Vue.js to handle the close event, when we click on the screen away from the intended object the object closes my problem here the click event does not work here's my code <template> <button v-if="action" @click="clicked" tabindex="-1" class="fixed z-40 w-full h-full inset-0 bg-black opacity-50 cursor-default" ></button> </template> <script> export default { name: "Overlay", props: { action: Boolean, }, methods: { clicked() { if (this.action === true)

click event as props in Vue.js

北战南征 提交于 2021-01-01 07:32:29
问题 I created a dynamic overlay component with Vue.js to handle the close event, when we click on the screen away from the intended object the object closes my problem here the click event does not work here's my code <template> <button v-if="action" @click="clicked" tabindex="-1" class="fixed z-40 w-full h-full inset-0 bg-black opacity-50 cursor-default" ></button> </template> <script> export default { name: "Overlay", props: { action: Boolean, }, methods: { clicked() { if (this.action === true)