My goal is to add a specific class
to an HTML tag, if that tag exists.
This is the code I have attempted:
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>index</title>
<style>
.black
{
background:#000;
color:white;
}
</style>
<script type="text/javascript">
$(window).load(function () {
$('textarea').addClass('black');
});
</script>
</head>
<body>
<div>
<textarea>content</textarea>
</div>
<script src="jquery.js"></script>
</body>
</html>
Desired Outcome: When the HTML body contains a textarea tag, I want the .black
class to be automatically applied to it.