Check your U.S. voter registration status or register to vote here.

IT STILL DOESN’T WORK — 3 more common problems we face in CSS, jQuery, and JavaScript (and their solutions)

Bahareh Adham
Aug 28, 2018 · 3 min read

A common problem with coding languages is that there is so many of them, and as soon as you finally feel comfortable with one, you get thrown eye-first into another, with its own set of idiosyncrasies. After only a few short weeks in the JavaScript vortex, I am here to provide you with 3 more problems I faced in my travels and how I solved them.


  1. My CSS backgrounds don’t work when I deploy them on my phone. Should I throw out my iPhone?

Next time you have this problem, check the background-attachment on the image in question. The culprit might be that it is ‘fixed’, which is a state that many mobile devices don’t support. You can work around this in many ways. I chose to put in a query that changes the background-attachment to “scroll” (aka the default) when on a touch device:

Image for post
Image for post

2. My ‘if’ statements in my script aren’t working! Are && and || a total lie??

Image for post
Image for post

Based on this, the answers “Trudeau”, “trudeau”, “justin trudeau”, and “Justin Trudeau” should all be correct. Let’s test it!

Tough question
Image for post
Image for post
Woohoo!

Yay! That works perfectly. Or does it?

Image for post
Image for post
Let’s try the wrong answer
Image for post
Image for post
Right again? What the??

SOLUTION: Every time you write an && or || logical operator, you need the start the next boolean expression from scratch. The correct way of writing the above code would be:

Image for post
Image for post

Let’s test it:

Image for post
Image for post
The more I read it the more I can’t figure out
Image for post
Image for post
So far so good!
Image for post
Image for post
Drum roll please…
Image for post
Image for post
Yas!

3. I’ve deployed my website, and some of my links just DON’T WORK on some devices! But they work on others! Am I taking crazy pills? Who invented this?

On my most recent project, I used jQuery to link my index.html page to another page of my website. I used the method windows.location.replace(‘file_path”);

Image for post
Image for post
Replaces the current location with this other location. Simple, right?

This worked perfectly fine while I was making the website. When I deployed it, something strange happened: the link would take you to a different URL depending on the device you use! My boyfriend and mom have the updated iOS on their phones, and their safari browsers linked them to a different URL than my older iOS phone’s — they received errors but I didn’t, although I did receive an error on my macbook’s safari. How could the same link take different devices to different places?

SOLUTION: The above method isn’t supported by all browsers. A better alternative would be to simply use windows.location.

Image for post
Image for post
So much better

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch

Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore

Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store