How to get position of ticks in D3

Getting the position of ticks in D3 is not as simple as inserting a function in the tick generating function. This is primarily becasue we get the ticks ready made when we call the d3.axis() function. However, using transform attribute it is possible to get the offset location of each individual tick.

The important thing to note is that when D3 creates an axis, it adds a class tick to each tick. So we can select all ticks using D3.selectAll(".tick"). Once we have a handle on all ticks, we can use each() on them for manipulation. The callback funciton receives data bound on each tick.

Credits: StackOverflow