Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

75
Views
decodeURI() is giving back a null html object

I'm working on a website where I get divs informations (like height) using a method where I get their id depending on the url, with anchors.

I somehow can't manage to make it work with url with space or special characters in them. It works fine with not spaced nor accented letters, but as soon as there are spaces (like in the example) it doesn't work.

I need them to work with spaces & accented characters though.

Here is the code. I think decodeURI() is making things work weirdly...

// My url as I load the page is : https://foo/#Le 10 décembre

// var strurl = window.location.href;
var strurl = "https://foo/#Le%2010%20d%C3%A9cembre";
var idOfText = /#(.+)/.exec(strurl)[1];
// it keeps "Le%2010%20d%C3%A9cembre"
var decodedIdOfText = decodeURI(idOfText)
// it gives me back "Le 10 décembre"

//now that I got this part of the url, 
//I need to find the matching element in my dom, using it's ID :

var x = document.getElementById(decodedIdOfText);
console.log(x)
// this console.log gives me : [object HTMLDivElement] 
// it should give me the specific div#Le 10 décembre

var textHeight = x.height();
// because I'm next supposed to get it's height.
// but there it gives me 
// Uncaught TypeError: x.height is not a function

<div class="text" id="Le 10 décembre">
    <a class="subtitle-texts" id="Le 10 décembre">Le 10 décembre</a>
    <div class="texts">
        <p>Le grand spectacle se termine, la chanson commence à se calmer, devenir plus tendre, le rythme est surement plus lent. Les voix sont reposées, les gestes sont lents</p>    
    </div>
</div>

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Update 1:
Observation 1: You have two elements with same id. The id is supposed to be unique.

<div ... id="Le 10 décembre">
    <a ... id="Le 10 décembre">Le 10 décembre</a>

Observation 2: Is there a good reason to make IDs with spaces, special characters and extended charset containing symbols like é? The IDs are always internal, not part of design, used only to be identified programatically. What is exactly the reason to do things that works against your program?

Look, I don't see a problem with your code. Try it in Mozilla javascript test

encoded="https://foo/#Le%2010%20d%C3%A9cembre";
console.log(decodeURI(encoded));
console.log(decodeURI(/#(.+)/.exec(encoded)[1]));

enter image description here

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!