Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using jQuery statements in plain javascript functions

Is it a good or bad practice to use jQuery statements in plain javascript functions outside of ready? If not what is the correct way?

//** End ready **//

function doSomething() {
    selectedClickBoxIndex = parseInt( jQuery('.' + clickBoxOnClass ).attr('value') );

    // Javascript code  
}
like image 762
James P. Avatar asked Apr 23 '12 13:04

James P.


2 Answers

nothing wrong. When you include the jquery file, you're expanding your functionality, free to use wherever you want

like image 108
Rodolfo Avatar answered Oct 12 '22 22:10

Rodolfo


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

You might want to use the function val, though:

function doSomething() {
  selectedClickBoxIndex = parseInt( jQuery('.' + clickBoxOnClass ).val() );

  // Javascript code  
}
like image 39
Guffa Avatar answered Oct 12 '22 21:10

Guffa