0

I want to attach a number to an element brought from database.

$(document).on("click", ".addnum", function () {
  
       ........

       $("#num-" + idd[1]).html(cki[1]);

                  
  });

in the above code, the selector, the $ part, is called from the database so basically it is not a fixed part in the body and the code works.

but in this part:

function checkcookie() {

    var cookiee = document.cookie.split("; ");

    for (let i = 0; i < cookiee.length; i++) {

        var c = cookiee[i];

        if (c.charAt(0) == "f" && c.charAt(1)== "o") {

            var cki = c.split("=");               //food-1 = 4        
            var idd = cki[0].split("-");         //food-1

            $("#num-" + idd[1]).html(cki[1]);            
        }
    }
}

the selector is again from database but it doesn't attach the value to it :(

Pointy
  • 405,095
  • 59
  • 585
  • 614
  • Welcome to Stack Overflow! This is a good opportunity for you to start familiarizing yourself with [using a debugger](https://stackoverflow.com/q/25385173/328193). When you step through the code in a debugger, which operation first produces an unexpected result? What were the values used in that operation? What was the result? What result was expected? Why? To learn more about this community and how we can help you, please start with the [tour](https://stackoverflow.com/tour) and read [How to Ask](https://stackoverflow.com/questions/how-to-ask) and **its linked resources** – Mister Jojo Mar 15 '23 at 22:36
  • So how is checkcookie() called? – epascarello Mar 16 '23 at 00:14
  • What, *exactly*, does `console.log("#num-" + idd[1])` give you? What about `console.log($("#num-" + idd[1]).length)`? – freedomn-m Mar 16 '23 at 06:17

1 Answers1

0

It's hard to understand what is going on without a console debug.

Read your console output and check for errors. If anything is getting wrong there, so your logic structure is kinda 'well' and the problem is with the selector itself.

Calling selectors with jquery, just sends or calls element blindly. Script is not listening if the selector was found. So if your console doesn't return error data, probably it's because the selector is not been called properly.

Try to debug selector text to the console and compare everything. Even if you are sure about what is happening.

Let me know if this was helpful. c:

JM.
  • 21
  • 1