Using jQuery statements in simple javascript functions

Is it a good or bad practice to use jQuery statements in simple javascript functions outside the box? If not the right way?

//** End ready **// function doSomething() { selectedClickBoxIndex = parseInt( jQuery('.' + clickBoxOnClass ).attr('value') ); // Javascript code } 
+6
source share
7 answers

nothing bad. When you include a jquery file, you expand your functionality, you can freely use it wherever you want.

+5
source

There is nothing wrong. jQuery is just a Javascript library, there is no strict separation between them.

You might want to use the val function, but:

 function doSomething() { selectedClickBoxIndex = parseInt( jQuery('.' + clickBoxOnClass ).val() ); // Javascript code } 
+3
source

This is perfectly acceptable; just make sure you call these functions after loading the DOM, either from the finished document or from the equivalent.

+2
source

There is nothing wrong.

What do you want to make sure that before the DOMReady, no DOM nodes are referenced. This is true whether you use $('.someClass') or document.getElementsByClassName .

Your function makes such a link, but this is normal until the function itself is called before DOMReady.

+2
source

There is no reason not to use it outside of the document. This greatly facilitates moving and changing dom.

Being able to grab elements on a page with many useful jQuery selectors is a good enough reason to use elsewhere.

+2
source

As long as the doSomething () function is fired after the onLoad event, everything is in order to do it this way. $ (document) .ready is just a way to defer JS execution until the page is fully loaded.

+2
source

Why not reduce the line of code, and also jquery is compatible with all browsers

+1
source

Source: https://habr.com/ru/post/913935/


All Articles