DOM not affected by addClass(), console log looks fine
up vote
0
down vote
favorite
I have a bunch of elements, all with the same class, and I'm trying to sort out what happens each time one of them is tabbed to. The tabbing event itself is fine, it's just this bit of code here that's giving me an issue.
Strangely, the result of the code below is that the console will log everything as expected (firstly the object that is in focus, then that same object with the new added class), however the DOM appears unaffected in devtools (ie no new class has been added). Thoughts?
$('.item__link').each(function() {
if ($(this).is(':focus')) {
console.log($(this));
$(this).addClass("test");
console.log($(this));
}
})
EDIT - here is the handler in its entirety:
$(window).on("keyup", function (e) {
// check that tab key has been pressed
var code = (e.keyCode ? e.keyCode : e.which);
if (code == 9) {
if ($('#main-menu__trigger').is(':focus') && !#main-menu__trigger.hasClass('open')) {
// do stuff
} else {
$('.item__link').each(function() {
if ($(this).is(':focus')) {
console.log($(this));
$(this).addClass("test");
console.log($(this));
}
});
};
};
code = 0;
});
jquery methods focus this each
add a comment |
up vote
0
down vote
favorite
I have a bunch of elements, all with the same class, and I'm trying to sort out what happens each time one of them is tabbed to. The tabbing event itself is fine, it's just this bit of code here that's giving me an issue.
Strangely, the result of the code below is that the console will log everything as expected (firstly the object that is in focus, then that same object with the new added class), however the DOM appears unaffected in devtools (ie no new class has been added). Thoughts?
$('.item__link').each(function() {
if ($(this).is(':focus')) {
console.log($(this));
$(this).addClass("test");
console.log($(this));
}
})
EDIT - here is the handler in its entirety:
$(window).on("keyup", function (e) {
// check that tab key has been pressed
var code = (e.keyCode ? e.keyCode : e.which);
if (code == 9) {
if ($('#main-menu__trigger').is(':focus') && !#main-menu__trigger.hasClass('open')) {
// do stuff
} else {
$('.item__link').each(function() {
if ($(this).is(':focus')) {
console.log($(this));
$(this).addClass("test");
console.log($(this));
}
});
};
};
code = 0;
});
jquery methods focus this each
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I have a bunch of elements, all with the same class, and I'm trying to sort out what happens each time one of them is tabbed to. The tabbing event itself is fine, it's just this bit of code here that's giving me an issue.
Strangely, the result of the code below is that the console will log everything as expected (firstly the object that is in focus, then that same object with the new added class), however the DOM appears unaffected in devtools (ie no new class has been added). Thoughts?
$('.item__link').each(function() {
if ($(this).is(':focus')) {
console.log($(this));
$(this).addClass("test");
console.log($(this));
}
})
EDIT - here is the handler in its entirety:
$(window).on("keyup", function (e) {
// check that tab key has been pressed
var code = (e.keyCode ? e.keyCode : e.which);
if (code == 9) {
if ($('#main-menu__trigger').is(':focus') && !#main-menu__trigger.hasClass('open')) {
// do stuff
} else {
$('.item__link').each(function() {
if ($(this).is(':focus')) {
console.log($(this));
$(this).addClass("test");
console.log($(this));
}
});
};
};
code = 0;
});
jquery methods focus this each
I have a bunch of elements, all with the same class, and I'm trying to sort out what happens each time one of them is tabbed to. The tabbing event itself is fine, it's just this bit of code here that's giving me an issue.
Strangely, the result of the code below is that the console will log everything as expected (firstly the object that is in focus, then that same object with the new added class), however the DOM appears unaffected in devtools (ie no new class has been added). Thoughts?
$('.item__link').each(function() {
if ($(this).is(':focus')) {
console.log($(this));
$(this).addClass("test");
console.log($(this));
}
})
EDIT - here is the handler in its entirety:
$(window).on("keyup", function (e) {
// check that tab key has been pressed
var code = (e.keyCode ? e.keyCode : e.which);
if (code == 9) {
if ($('#main-menu__trigger').is(':focus') && !#main-menu__trigger.hasClass('open')) {
// do stuff
} else {
$('.item__link').each(function() {
if ($(this).is(':focus')) {
console.log($(this));
$(this).addClass("test");
console.log($(this));
}
});
};
};
code = 0;
});
jquery methods focus this each
jquery methods focus this each
edited Nov 8 at 10:33
asked Nov 8 at 9:34
devosaurolophus
62
62
add a comment |
add a comment |
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53204923%2fdom-not-affected-by-addclass-console-log-looks-fine%23new-answer', 'question_page');
}
);
Post as a guest
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password