I’m trying to Create user define $ function as i cannot use Jquery in existing project.
I want to get this function as work as Jquery $(‘ID’)
Please give me some hint Any hint OR Example
for Example
function $(element) {
}
var value = $('elementID').value
UPDATE:
As i have prototype.js
function $(element) {
if (arguments.length > 1) {
for (var i = 0, elements = [], length = arguments.length; i < length; i++)
elements.push($(arguments[i]));
return elements;
}
if (Object.isString(element))
element = document.getElementById(element);
return Element.extend(element);
}
You can start with:
However, you’ll eventually find that that is not good enough. Internet Explorer (in older versions), it turns out, returns values by name too. In other words, if there’s an element on the page whose “name” attribute matches the “id” you’re looking for, you (might) get that instead.
Thus, you have to actually do more work than that. I recommend checking the source to jQuery or Prototype to find the state-of-the-art way that smart people are dealing with that problem. edit wow in jQuery it’s fairly complicated.