JavaScript jquery.data returning undefined results jquery data returning undefined,jquery ajax return data,jquery post

I'm trying to use the jquery.data method to retrieve a bunch of item's IDs from a node server and save it for each item as an attr or data and use it later for updating the item.

But the attribute always returns "undefined".
I tried .data and .attr and both have the same result. To elaborate more: what I'm trying to do is get a list of elements from the server create li tags dynamically for each one, then somehow embed the ID that is coming from the server in each created HTML element as a custom attribute or an ID. What am I doing wrong? and is there another way to do this?

var test = "<p>Hello</p>";
$(test).data("id", 1);
console.log($(test).data("id")); //undefined
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
Answer:1

$(test) creates an object. So when you want to log the id, you are creating another object and tries to read the data-id of it, which is absent. Create and keep the object reference in a separate variable and use that in the rest part.

var test = "<p>Hello</p>"
var jTest = $(test);
jTest.data("id", 1);
console.log(jTest.data("id"))
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
Answer:2

In Polymer 1.0+, how do you pass in a template from the light dom to be used in the dom-module? I'd like the template in the light dom to have bind variables, then the custom element use that template ...

In Polymer 1.0+, how do you pass in a template from the light dom to be used in the dom-module? I'd like the template in the light dom to have bind variables, then the custom element use that template ...

  1. polymer candy clay
  2. polymer cane
  3. polymer cane patterns
  4. polymer cane slicer
  5. polymer canes for sale
  6. polymer cane tutorial
  7. polymer candy clay liquid
  8. polymer candy clay amazon
  9. polymer candy clay for phone case
  10. polymer cane tutorials free
  11. polymer canada
  12. polymer canoe
  13. polymer cancer treatment
  14. polymer canada notes
  15. polymer canadian money
  16. polymer candy
  17. polymer canvas
  18. polymer cancer
  19. polymer cane extruder
  20. polymer candle filter

It is hard to explain, you can see a DEMO HERE I have a products table that dynamically creates/deletes new lines of products. I also have a totals table that totals up the totals of each line ...

It is hard to explain, you can see a DEMO HERE I have a products table that dynamically creates/deletes new lines of products. I also have a totals table that totals up the totals of each line ...

I have a button. onClick the button fires a JS function. In this function on the very first line of code I change the button's HTML using jQuery. Then the function takes a couple seconds. The button ...

I have a button. onClick the button fires a JS function. In this function on the very first line of code I change the button's HTML using jQuery. Then the function takes a couple seconds. The button ...

  1. canvas
  2. canada
  3. cancelled
  4. canceled vs cancelled
  5. canada goose
  6. cancun flights
  7. cane corso
  8. canes
  9. canadian prime minister
  10. canker sore
  11. candy
  12. cancer
  13. cancun
  14. canon
  15. canvas prints
  16. cancer sign
  17. candace owens
  18. canada news
  19. candytopia
  20. canlis

I have successfully been able to call an API using python requests library. Need to make the same request in node.js. Saw various Q&As on SO and tried hard with the request library in node.js but ...

I have successfully been able to call an API using python requests library. Need to make the same request in node.js. Saw various Q&As on SO and tried hard with the request library in node.js but ...

  1. send post request javascript
  2. send post request python
  3. send post request curl
  4. send post request from chrome
  5. send post request online
  6. send post request java
  7. send post request postman
  8. send post request c#
  9. send post request powershell
  10. send post request php
  11. send post request from command line
  12. send post request golang
  13. send post request react
  14. send post request js
  15. send post request from terminal
  16. send post request html
  17. send post request in url
  18. send post request node
  19. send post request with parameters
  20. send post request to localhost