2

My knowledge of Jquery & Javascript is limited at best, but I'm under the impression JQuery is basically a simplified version of JavaScript.

If that is the case is there a way of converting this code to Javascript so I don't have to call the JQuery Library as it seems to be causing other JavaScript Functions to not work?

function toggleStatus(mynum) {
    $('#product_'+mynum+'_submit_button').removeAttr('disabled');
}
3
  • 1
    You probably want to use jQuery.noConflict(); Commented Feb 2, 2012 at 17:18
  • 3
    jQuery is Javascript. It's a Javascript library. Commented Feb 2, 2012 at 17:18
  • If your page is already importing another library that uses "$", chances are that what you really need to do is convert that code there to the equivalent for the library your page uses. Commented Feb 2, 2012 at 17:19

5 Answers 5

7

This should work :)

var d = document.getElementById('product_'+mynum+'_submit_button');
d.removeAttribute('disabled');
Sign up to request clarification or add additional context in comments.

1 Comment

+1 since it's equivalent, but I'd probably set the disabled property to false instead of removing the attribute.
5

jQuery is not a simplyfied version of javascript, but a javascript library that enables you to work rather effortlessly with the dom.

the code could be rewritten like that:

var e = document.getElementById('product_'+mynum+'_submit_button');
if( e ) e.removeAttribute('disabled');

Comments

3

The native version of that code would

  • set the disabled property on the element instead of messing with the attribute

  • use document.getElementById to select an element by id in lieu of jQuerys $("#id"):

var element = document.getElementById('product_' + mynum + '_submit_button');
element.disabled = false;

Also note that, for future reference, the native equivalent for jQuery's removeAttr is removeAttribute

2 Comments

+1 for including docs... ah, and you updated to set the property instead of removing the attribute. Very good. :)
@amnotiam - indeed - twas your comment above that kicked me in the pants. +1 to you :-)
0

Which other Javascript function's aren't working? jQuery is a Javascript framework to help you achieve Javascript tasks more easily, as well as create other functionality like animations.

If you're looking to simply convert what you have there into Javascript, you could do this:

function toggleStatus(mynum) {
    document.getElementById('product_'+mynum+'_submit_button').removeAttribute('disabled');
}

I have a feeling like this could be the beginning of more Javascript and jQuery questions as you quest to learn more! Good luck! :)

Comments

0

Jquery is not simplified version of javascript. Think it as a library instead. The common functionalities which are needed for our development are simplified and organized in single library. For using that functionalities you have to read its API (Application Programming Interface) documentation. It will help you to write less code as compared to normal javascript code. I think, Jquery will not be the cause of problem in your code. Any way for writing this code in pure javascript you can follow below code:

document.getElementById('buttonId').removeAttribute('disabled');

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.