What is jquery anyway

In the background, does jquery use regular javascript, or is jquery an alternative to javascript?

If Jquery does use javascript in the background, then couldn’t anything done in jquery be accomplished in javascript?

The reason I asked this is: I see some javascript questions, and some replies refer the person to jquery and how easy it is, but they don’t give a detailed answer with an example.

Furthermore IF AND ONLY IF, jquery relies on javascript, wouldn’t a detailed answer in javascript be better? Someone wrote jquery! Now if you only rely on jquery, you will never be as smart as the person who used javascript to write jquery!

Bottom line: The person who wrote jquery wrote javascript to write jquery.
Tricky ain’t it! To repeat:
The person who wrote jquery wrote javascript to write jquery.
So why do some of you seem to hate javascript so much?

Hi,
JQuery’s main goal is to provide a developer with an easy way to handle DCOM objects with CSS and XPath selectors. It is not in any way a replacement for JS. You can look at it as a JS library.
Chhers.

I don’t use much javascript. I might return some info from a child to a parent form with code like this.


function cell(id)
{
var x=document.getElementById('myTable').rows[id].cells;
opener.document.editform.ownerid.value = x[0].innerHTML;
opener.document.editform.petowner.value = x[1].innerHTML;
opener.document.editform.ostreet.value = x[2].innerHTML;
// or opener.document.editform.ostreet.value = x[2].FirstChild.NodeValue;
// FirstChild.NodeValue works as well...
self.close();

}


Could someone show how this would look in jquery?
In the above each tr obviously has a unique id. I am filling some fields on parent from another popup window/table.

Again I hardly use much javascript except for such as this to return some data.

Jim, it really depends on your understanding what is jQuery or even other frameworks. What i have understood about jQuery so far is:

jQuery is a JavaScript framework or better say collection functions written in JavaScript itself. so jQuery is a JavaScript framework which has lots of functions in it and then a jquery functinon/method can be called to perform a particular task. If you write your own JavaScript for the same purpose then you may need to write at least 100 lines. So using existing frameworks of any language not only JavaScript is to reduce your time.

For example if you want to slide down a div instead of just show/hide upon a click of a check box, i cannot imagine that you can write it within a minute with normal JavaScript but jQuery has already a method/function that does for you (jQuery(“divtoslide”).slideDown(‘slow’). And i believe jQuery is a framework that is well tested before it is released.

There are other JavaScript frameworks too like mootools, dojo, prototype, etc. jQuery is not only one available. It depends on you which to use in your case but jQuery is my favorite one. But still I would recommend all the programmers to understand JavaScript very well before you use any frameworks.

So it can be explained in this way, instead of reinventing the wheel, it is better to use an existing and well tested working wheel :wink:

JQuery is just a collection of code written in JavaScript that someone else has already tested for you. It is no different from JavaScript that you could write for yourself apart from the time it would take you to code and test it. The trade-off is that you generally end up having to include the entire library even if you are only using a small part of it.

So it all comes down to whether you want to use a general all-purpose extremely heavy wheel or to make your own much lighter wheel that is more specific to the vehicle you want to use it on.

I tryed to call your example, putting in in place of my code, and nothing happened.

<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript">
function cell(id)
{
$(['ownerid', 'petowner', 'ostreet']).each(function (index) {
    $(opener.document.editform)
    .find('[name="' + this + '"]')
    .val($(x[index]).html());
});
self.close();

}
 
</script>

What would the whole thing look like including calling it? My example depends on a row clicked.

if you’re wanting firstchild.value you could use this instead:


$('input:first', x[index]).val()

That is, if the form field you’re getting the value from is an input element.

jQuery is not a different language from javascript; it just provides certain abstractions to make parts of javascript easier to use. jQuery is still fully javascript, so self.close() works just the same.
To my knowledge, jQuery doesn’t provide any helpers to assist with that, though you can go to http://docs.jquery.com/Main_Page and have a quick look through the API Reference.

$(['ownerid', 'petowner', 'ostreet']).each(function (index) {
    $(opener.document.editform)
    .find('[name="' + this + '"]')
    .val($(x[index]).html());
});

Would the .val($(x[index]).html()); be innerhtml or firstchild.nodevalue?
Though my example uses innerhtml, I actually use firstchild.nodevalue.
And does jquery have a self.close();
like in my example?

I really like javascript, but I don’t like the browser environment that the code executes in - there’s sooo many browsers and platforms, each with their own stupid little differences. It’s an incredibly huge undertaking to write good cross browser code. It’s foolish to think that some simple testing will net you the same quality as a major library like jquery. You need to be aware of the bugs and differences in order to avoid them, or work around them. That’s a very tall order…Look at the bug database of one of the javascript libraries, and you’ll see how many obscure differences there really are.

The existence and size of the bug databases kinda highlight an important point - even the authors of the libraries, who should be considered very experienced programmers in the javascript/browser domain, write code that isn’t perfect, or accommodating of browser xyz version x.xx…

The syntactic shortcuts and various functions are also very very nice, but in my opinion, the real gem is that the library is like a huge compatibility layer that’s been very heavily battle tested.

So basically, while I think it’s a great idea to learn javascript in detail, especially some of the more advanced parts of it as well as the native dom interface, I think the whole cross browser compatibility issue is something that is very tough to tackle on your own if you want highly robust code. It’s not difficult to write cross browser code without a library, that works decent for many common tasks. But there will be obscure edge cases where the code is more likely to misbehave or fail.

jQuery uses regular javascript, so it’s not an alternative to it, but an addition to it, if you will.

Completely true. Problem is that javascript that works in one browser doesn’t have to work in another browser. Just like HTML/CSS behaves differently across different browsers, javascript also behaves differently across different browsers. The functions jQuery gives you are written in such a way that they work across all browsers, thus eliminating the need for programmers to take into account browser differences for themselves.

See the signature of Stomme Poes: I got a FEVER, and the only PRESCRIPTION…is MOAR jQuery!! :smiley:

Which raises the question do you have to be as smart as the person who wrote jQuery. I can move my mouse in windows, but I have no idea how that’s implemented. Does that make me not as smart as the person who wrote that? Should I care?

I guess it’s not that some of us hate javascript in itself, but hate how it’s used sometimes. What I mean with this is that some websites rely on javascript so much that the whole website comes crumbeling down when javascript is disabled / not available. Or people use it to achieve something that could have just as easily been achieved using CSS, like giving links a different color when you hover them.
In the thread Why web standards can cripple the web there’s a whole discussion on this very same topic. Might want to check it out.

I’ll be able to provide a tested solution at some later time today.

If the id variable is not an actual unique identifier, then the only difference there would in using $(‘myTable’) instead of document.getElementById(‘myTable’)

In regards to the opener part, you could do something like:


$(['ownerid', 'petowner', 'ostreet']).each(function (index) {
    $(opener.document.editform)
    .find('[name="' + this + '"]')
    .val($(x[index]).html());
});