Using .data("x") instead of of .attr("data-x") is fine.
One thing I want to point out is that data() will convert the data type of the value, but .attr() does not.
Since we're not working with numbers here it's no problem. (just wanted to make sure that you are aware of this)