The ‘this’ keyword in jQuery is a very handy tool in your programming toolkit. If you are writing generic functions or you just can’t be bothered writing the id for the DOM element or if you are trying to access any of the child objects of a DOM, the $(this) object is the object for you.
I’ll save the finer details of jQuery’s ‘this’ keyword for another day and assume you have some knowledge about it already or you are just curious as to accessing the child elements of a $(this) object.
An example of what I’m talking about:
You can use jQuery’s ‘this’ to get a selector for any of the child elements inside “exampleDiv”. You could set the anchor’s inside the div to have an underline on hover for example:
jQuery("#exampleDiv").hover(
function () {
jQuery("a",this).css({textDecoration: ‘underline’});
},
function () {
jQuery("a",this).css({textDecoration: ‘none’});
}
);
});
</script>
This kind of thing can come in very handy now and then and I have also found it can sometimes help with browser bugs as well.
I’m a jQuery newbie so I have just learned the fundamentals and getting comfortable using the simple codes. So I appreciate learning something new about it, thank you!