Reputation: 949
Instead of repeating a function for every ID of my elements, I would like to use "this" to adjust the CSS of an internal element. For instance, this is how far I've gotten (doesn't work).
$(".parent").hover(function() {
$("this").find(".child").css("height","150px")
});
How can I become a more efficient coder and use "this"?
Upvotes: 0
Views: 64
Reputation: 3999
Heres a solution that does not require jQuery:
someElement.addEventListener('mouseover', function(e) {
var children = Array.prototype.slice.call(e.target.children);
children.forEach(function(child) {
child.style.height = '150px';
});
}, false);
Upvotes: 0
Reputation: 6124
Change it to
$(".parent").hover(function() {
$(this).find(".child").css("height","150px")
});
So that there are no quotes.
Upvotes: 2
Reputation: 725
Remove quotations from "this" and it'll work. A common mistake :)
code like this:
$(this).find(".child").css("height","150px")
Upvotes: 3