Here is my selector in native JavaScript:
const textarea = document.getElementsByTagName("textarea")[0];
What is the equivalent in jQuery?
I have tried this with no luck:
const textarea = $("textarea")[0];
Here is another example:
<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
$(".btn1").click(function(){
const textarea = $("p")[0];
textarea.fadeOut();
});
$(".btn2").click(function(){
$("p").fadeIn();
});
});
</script>
</head>
<body>
<p>This is a paragraph.</p>
<button class="btn1">Fade out</button>
<button class="btn2">Fade in</button>
</body>
</html>