I have this JavaScript functions that I want to convert to jquery but I can't understand jquery. It uses the document.getElementsByName
a lot so I would like to know how to convert the document.getElementsByName
into jquery.
function getElements(name){
if (document.getElementsByName(name)[0].className == "visible"){
document.getElementsByName(name)[0].className = "hidden";
} else {
if(document.getElementsByClassName('visible')[0] != null){
document.getElementsByClassName('visible')[0].className = "hidden";
}
document.getElementsByName(name)[0].className = "visible";
}
}
jQuery is a JavaScript library, so it operates on top of JavaScript. It cannot exist on its own, so you can't use one over the other. You can use just JavaScript or JavaScript and jQuery.
Converting a JavaScript codebase over to TypeScript is, while somewhat tedious, usually not challenging. In this tutorial, we're going to look at how you might start out. We assume you've read enough of the handbook to write new TypeScript code.
“This” keyword refers to an object that is executing the current piece of code. It references the object that is executing the current function. If the function being referenced is a regular function, “this” references the global object.
you can try with attribute selector...
$('[name="'+name+'"]') //for name selector
$('.visible') //for class selector
You should try because when you try practicing you actually are learning:
document.getElementsByName
in jQuery $("[name=Name]");
document.getElementsById
in jQuery $("#IdofElement");
document.getElementsByClass
in jQuery $(".ClassofElement");
Here are some tutorials:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With