Reputation: 267
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');
}
Upvotes: 2
Views: 1533
Reputation: 23
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');
Upvotes: 0
Reputation: 83358
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
Upvotes: 3
Reputation: 9661
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! :)
Upvotes: 0
Reputation: 11278
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');
Upvotes: 5
Reputation: 602
This should work :)
var d = document.getElementById('product_'+mynum+'_submit_button');
d.removeAttribute('disabled');
Upvotes: 7