0

I'm adding titles to existing divs. I'm using Visual Studio's Live Server and it works perfectly but when I upload it on Netlify it gives me "null" error. I can't figure out why is it doing that. Here's the part of the code where's the error:

while (suratebiNames < 398) {
    var img = document.getElementById("meme" + suratebiNames);
    img["title"] = text.split("\n")[suratebiNames].toLowerCase();
    suratebiNames++;
}
Heretic Monkey
  • 11,687
  • 7
  • 53
  • 122
  • By "null error" do you mean `img` is `null`? – David Sep 20 '22 at 18:42
  • 1
    "null" isn't an error. Since we can't run your code, can you provide the exact error message please. – James Sep 20 '22 at 18:42
  • 1
    Uncaught (in promise) TypeError: Cannot set properties of null (setting 'title') - Exact error message –  Sep 20 '22 at 18:43
  • @Gurami30: That error means `img` is `null`, which means `getElementById` didn't find the element it was looking for. – David Sep 20 '22 at 18:44
  • I know what the error means but it's there. It works on `Live Server` and not in `Netlify` –  Sep 20 '22 at 18:46
  • @Gurami30: *"but it's there"* - `getElementById` disagrees with you, and it's usually right about these things. Perhaps the element doesn't exist at the time this code runs but is added after? Perhaps one of the multiple elements you're looking for is missing and you didn't notice? Without a runnable [mcve] to demonstrate the problem, all we can do is guess. But if you're asking us to simply *believe you* over the observable results of testing the code, that's unlikely to be of any help to you. – David Sep 20 '22 at 18:48

0 Answers0