Jump to content

Change src attr


slj90

Recommended Posts

I have a navigation bar that allows the user to change the color scheme of the site (logo and background)

 

The javascript I am using works, it changes it from one color to another, however, if the user selects the color that is already selected the logo disappears:

function colorRed() {
 document.body.style.backgroundColor = "#b20a22";
$("#logo").fadeOut(function() { 
  $(this).load(function() { $(this).fadeIn(); }); 
  $(this).attr("src", "./redlogo.png"); 
}); 

Thanks

Link to comment
Share on other sites

Since I do not use jQuery because I prefer JS, I can only give you ideas.

 

I'd suggest you check beforehand what color the user has selected and if it is the same color as the current one, then you don't run the script that changes the color.

Edited by Stefany93
Link to comment
Share on other sites

Since I do not use jQuery because I prefer JS, I can only give you ideas.

Still anti-jQuery eh? You do know that jQuery is js right? The solution you offered up would be the same syntax, even the "jQuery" way, because jQuery is js. If you are coding vanilla js properly, under the hood it's going to be the exact same as jQuery. The only benefit not using it is for example if you have a simple site with minimal js needs in which case jQuery or the like is extra bloat. Not that it's *that* big a deal, what with ability for things to be cached and all..

 

I do appreciate someone who likes the vanilla way.. lord knows I've been having much trouble trying to hire someone who actually knows vanilla js.. but you're only hurting yourself by not learning frameworks like jQuery. What if you come across a client willing to throw lots of money at you to fix something or dev something but requires knowledge of jQuery? Sure would be a shame turning that down.. Or..what if they hire you to do something for them and you do it the vanilla way and they're all like "Uh.. we have jQuery on the site.. what's with all this extra unnecessary code?" Are you gonna argue with them your (misguided) principles?

Link to comment
Share on other sites

Still anti-jQuery eh? You do know that jQuery is js right? The solution you offered up would be the same syntax, even the "jQuery" way, because jQuery is js. If you are coding vanilla js properly, under the hood it's going to be the exact same as jQuery. The only benefit not using it is for example if you have a simple site with minimal js needs in which case jQuery or the like is extra bloat. Not that it's *that* big a deal, what with ability for things to be cached and all..

 

I do appreciate someone who likes the vanilla way.. lord knows I've been having much trouble trying to hire someone who actually knows vanilla js.. but you're only hurting yourself by not learning frameworks like jQuery. What if you come across a client willing to throw lots of money at you to fix something or dev something but requires knowledge of jQuery? Sure would be a shame turning that down.. Or..what if they hire you to do something for them and you do it the vanilla way and they're all like "Uh.. we have jQuery on the site.. what's with all this extra unnecessary code?" Are you gonna argue with them your (misguided) principles?

 

I will say that I resisted JQuery for years. Mostly because I felt I would be giving up control and be limited.Plus, I wasn't interested in learning a new 'language' to do things that I could do with vanilla JS. I'm a hobbyist so learning new languages/frameworks is only something I do if I am interested in it.

 

There was a relatively short learning curve and I sometimes struggle on syntax since I have not worked with it as long. But, I have been able to build things very quickly that would have taken me many times longer without JQuery. And it was built to be extremely extensible. So, if I don't like the default behavior for a particular function (or want tit to do something additional) it is typically as simple as creating my own function and "plugging it in".

Link to comment
Share on other sites

Still anti-jQuery eh? You do know that jQuery is js right? The solution you offered up would be the same syntax, even the "jQuery" way, because jQuery is js. If you are coding vanilla js properly, under the hood it's going to be the exact same as jQuery. The only benefit not using it is for example if you have a simple site with minimal js needs in which case jQuery or the like is extra bloat. Not that it's *that* big a deal, what with ability for things to be cached and all..

 

I do appreciate someone who likes the vanilla way.. lord knows I've been having much trouble trying to hire someone who actually knows vanilla js.. but you're only hurting yourself by not learning frameworks like jQuery. What if you come across a client willing to throw lots of money at you to fix something or dev something but requires knowledge of jQuery? Sure would be a shame turning that down.. Or..what if they hire you to do something for them and you do it the vanilla way and they're all like "Uh.. we have jQuery on the site.. what's with all this extra unnecessary code?" Are you gonna argue with them your (misguided) principles?

 

 

WOW you really hate me, don't you sir? As a matter of fact at my company I had been given tasks to solve jQuery issues and guess what - I did them because I know perfect JS. There is absolutely no damn need to learn jQuery if you know Javascript since you will be wasting your time. jQuery was made for people who are not-so-smart to learn JavaScript and guess what? Now the majority of people who call themselves programmers can't write a line of Javascript. Do you have any idea how slow jQuery is? How much it slows down the web-page? 

 

And the "less typing" nonsense? We are PROGRAMMERS it is our JOB to type code. If we don't like that we can always wear the blue collar and be done with it.

 

The greatest programmers that exists and those that I know personally only use JS and NEVER jQuery. I believe that is a proof enough.

Link to comment
Share on other sites

I don't hate you. I just don't like your attitude about jQuery. More importantly, I don't like how that attitude manifests in your posts, how you look down on people who use it or even mention it.

 

You talk about all these not-so-smart people who call themselves programmers but can't write a line of javascript because they are wasting their time with jQuery, and I don't necessarily disagree with you, but running around pointing this out and how you aren't one of those not-so-smart people doesn't help the situation. All it does is make you sound like a pretentious, elitist asshat.

 

You weren't really interested in helping OP out. All you really wanted to do was get on your soapbox and wag your finger at OP about jQuery, and then you threw out a few half-hearted words pointing vaguely in the right direction to try to justify it. This makes you look like a pretentious, elitist asshat offering up no actual solution.

 

If you are truly here to help and stick to your (misguided) anti-jQuery principles, then help end this pandemic of stupidity by posting a pure js solution and explaining to the OP how it works and why it is a better solution. Otherwise, don't post at all, because as Dr. House taught us, people only tolerate pretentious, elitist asshats if they also provide actual solutions.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.