Conversion of DOM element selection code to jQuery
Posted
by Tom McDonnell
on Stack Overflow
See other posts from Stack Overflow
or by Tom McDonnell
Published on 2010-05-03T12:16:37Z
Indexed on
2010/05/03
12:28 UTC
Read the original article
Hit count: 272
I have a large Javascript codebase to convert to jQuery. The code is structured such that DOM elements are created in Javascript (using a library called DomBuilder), and saved to variables if they will be needed later, before being added to the DOM.
Eg.
var inputs =
{
submitConfirm: INPUT({type: 'button', value: 'Submit'}),
submitCancel : INPUT({type: 'button', value: 'Cancel'})
};
document.appendChild(inputs.submitConfirm);
Then later for example...
inputs.submitCancel.style.display = 'none';
inputs.submitCancel.addEventListener('click', onClickSubmitCancel, false);
My problem is that jQuery seems to lack a way of manipulating DOM elements directly, as opposed to selecting them first (with for example $('#submitCancel').
Can anyone suggest a way to directly translate the last two Javascript lines given above to use jQuery, given that the DOM elements are already available, and so do not need to be selected?
© Stack Overflow or respective owner