score:1
Accepted answer
Attaching a click handler in that way will result in the scope of the function being set to the button element itself. You could therefore replace the whole event.target section with either the jQuery:
$(this).attr('name');
or raw JavaScript:
this.getAttribute('name');
score:-1
You have to pass e as a parameter.
button.attr("name", i).on("click",function(e) {
var target = (e.target) ? e.target: e.srcElement;
alert(target.name);
});
Léon
score:1
Why don't you use parameter e.g
button.attr("name", i).on("click",function(e) {
var target = (e.target) ? e.target: e.srcElement;
alert(target.name);
});
More Info
$("#dataTable tbody tr").on("click", function(event){
alert($(this).text());
});
according to: http://api.jquery.com/on/
Source: stackoverflow.com
Related Query
- Get reference to target of event in d3 in high-level listener?
- Firefox click event buggy
- In d3 on blur event is not working in firefox only
- D3 event showing 'ReferenceError: event is not defined' in Firefox
- Target this->sibling with mouse event
- d3.js 'mousewheel' event is NOT working on Firefox (it works only in Chrome, Safari and IE browsers)
- responsive canvas on window resize event
- d3 dragging event does not terminate in Firefox
- Target other elements on d3.js on event
- ReferenceError: event is not defined firefox d3.js
- How to stop shift + mouseClick opening up a new window in Firefox
- Window.event target on Firefox
- Why is the window resize event appending the g element repeatedly?
- How to add an event listener to entire window except for a defined donut (or annulus)
- Resize svg when window is resized in d3.js
- How to invoke "click" event programmatically in d3?
- Attaching 'onclick' event to D3 chart background
- How can I make double click event on node in d3.js?
- d3.js Map (<svg>) Auto Fit into Parent Container and Resize with Window
- Why doesn't click event always fire?
- d3.js - mouseover event not working properly on svg group
- How to add a click event on nvd3.js graph
- Determine if Shift key is pressed during mousedown event
- SVG renders but gets cut off in Firefox only - why?
- Using ViewBox to resize svg depending on the window size
- d3.js transition end event
- SVG element loses event handlers if moved around the DOM
- d3 - trigger mouseover event
- nvd3.js : unable to bind onClick event with the data points in the svg
- Is there a tap and double tap event in d3.js force directed graph
More Query from same tag
- Multiple straight line between two node in d3.js
- Detect if click is inside OverlayView
- Error: Invalid value for <g> attribute transform="translate(undefined,undefined)"
- Cannot read property "0" of undefined
- How do I resolve this bug in d3 js while applying .ticks() to my x scale
- d3js select circle with specific text label
- Combining two d3 visualization
- D3 V4 Properly placing a bubble in the US Map
- d3 enter() / merge() creates copies instead of updating
- d3 binding data to a group does not seem to propagate after creation
- Converting stroked path to shape with javascript
- I want to create a data-driven network, I'm trying to use d3
- d3.js replace circle with a foreignObject
- d3 - achieving replay
- Efficient data storage, partitioning, and selection in d3
- How to remove the header of a D3JS tooltip?
- d3 v4: Stacking nested data?
- How do I used D3 to force a user click on a circle object inside of a g.node object?
- d3 ignore SVG on selectAll
- How to modify and copy observablehq zoomable sunburst to a local machine and run?
- d3.js not able to parse my string into date despite seemingly correct format? (v4)
- D3.js: Text labels dissapear when I click on the second svg element
- d3 Reusable histogram
- D3 Pack text weird behavior
- d3 line disappears on data update
- Maintain color mapping for Stacked/Grouped Multi-Bar Chart using NVD3 when the series count fluxuates
- How to animate an element to follow an arc's centroid in d3?
- unable to change legend symbol nvd3 bubble chart
- Get values from D3 line interpolator functions
- Fix tooltips on horizontal bar chart d3.js