anon
anon

Reputation:

To use or not to use jQuery?

I have an <img id="mypic"> that i need to change with an interval its src.

Should I use jQuery or not?
Should I do:

or

Upvotes: 1

Views: 147

Answers (3)

Dejan Marjanović
Dejan Marjanović

Reputation: 19380

You should not use jQuery if you don't know how to do it in plain Javascript. Looks like you know, feel free to use it :)

Upvotes: -2

Zach Rattner
Zach Rattner

Reputation: 21361

Use JQuery if the benefit of having convenient selectors and AJAX support is worth the 29 KB it'll add to your page download time. For most of my uses, it is worth is.

Also, for your JQuery code snippet, the $ character is the JQuery selector. So, you can do this:

$('#mypic').attr('src','src2');

In my opinion, JQuery is very concise, and you can get a lot done once you get used to it.

Upvotes: 1

mattsven
mattsven

Reputation: 23303

It...doesn't really matter. I'd say use jQuery if you are using it in other places in your code, otherwise..it is up to you. However, if you are doing this in an interval, it would be slightly (but not noticeably) faster to use natural JS.

Upvotes: 4

Related Questions