I have the following JSON object:
var definitionsObject = {"company" : "Some information about company"};
This object will actually contain a lot of definitions, not just one. And I also have the following event handler for a link click which has a custom “data-name” attribute containing the term “company”:
$(".definitinOpener").click(function() {
$this = $(this);
var hintID = $this.attr("data-name");
var hintText = definitionsObject.hintID;
});
So, what I’m trying to do is get the value of “data-name” custom attribute of the clicked link, go to the definitionsObject object and get the value of the field which is equal to the “data-name” attribute value. However in this way I’m always getting “undefined”.
Could anybody please help me to figure out what exactly I’m doing wrong?
Thank you beforehand.
You can look up a value in an object in two ways.
You probably want this: