I'd like to get a value of id attribute for an input tag.
<input type="text" id="heading1" class="alert-heading" value="aaa" />
In order to to this, I wrote this code.
var alertHeading = $(".alert-heading");
alertHeading.on('blur', function(){
var headingId = $(this).attr("id");
console.log(headingId); // outputs 2943. I'm expecting "heading1".
});
But, I get a weird number when I get an access to id although I'm expecting to get a "heading1".
This is the code that I'm working on right now.
var alertHeading = $(".alert-heading");
alertHeading.on('blur', function(){
var key = alertMode.val();
chrome.runtime.getBackgroundPage(function(backgroundPage) {
var background = backgroundPage.background;
var alertObject = background.getStorage(key);
//(EDITED)Oh I think $(this)here no longer points to the input element!!
var headingId = $(this).attr("id");
console.log(headingId); // outputs 2943. I'm expecting "heading1".
});
})
Please help me out to solve this problem. Thanks in advance!