Reputation:
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:
document.getElementById('mypic').src='src2';
or
jQuery('#mypic').attr('src','src2');
Upvotes: 1
Views: 147
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
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
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