Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Doesn't jQuery('#id') do the same thing as document.getElementById('#id') in javascript? [duplicate]

Possible Duplicate:
document.getElementById vs jQuery

I have a function that will take all the spans with a certain class ("jobStatus") and remove an additional class from it ("orange"). I call the function from a SELECT onchange (onchange="chgJobstatus(this);"). It's working great.

However, I'm trying to get it to run on page load, based upon the selected value (this is server-side dynamically generated.)

This will work:

     $(document).ready(function(){
          chgJobstatus(document.getElementById("chgStatus"));
     });

This will NOT work:

     $(document).ready(function(){
          chgJobstatus(jQuery('#chgStatus'));
     });

Doesn't jQuery('#id') do the same thing as document.getElementById('#id') ??

like image 202
Sameera Thilakasiri Avatar asked Jun 15 '26 05:06

Sameera Thilakasiri


1 Answers

Regarding selecting the element, yes, but jQuery selectors return jQuery objects and getElementById returns a DOM Element object, you can get the DOM Element using [index] or get(index) method:

chgJobstatus(jQuery('#chgStatus')[0]);
like image 140
undefined Avatar answered Jun 16 '26 17:06

undefined



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!