I am using the following code:
$(targetSelector)
.attr({
'data-disabled': 'yes',
'data-title': function() { return this.title },
'title': ''
})
.addClass('disabled')
.prop('disabled', true);
This sets the element’s title to ” after first having stored it in data-title.
How can I restore the elements title by getting it back from the data-title attribute if the title is currently equal to the empty string? I assume I need to do this in a function like the above but how can I code in a check into the function?
You can try this:
If will return the title if it is falsy, else it will grab the data-title attribute.