I did spend a bit of time to discover how to check if data- attribute is defined on an object, so might as well write it down.
It’s not a rocket science, and very googleable, but it’s my blog, right? I can write here whatever I want, right?
So here you go:

$(".some-class").data("width") !== undefined
  • Alireza Noori

    Thanks. I didn’t know this one :D

  • Thomas Williams

    Thank you. This solved my problem