JavaScript Simple AJAX help request: significance of “+=” applied to string

myDiv.innerHTML += "Request status: 1 (loading) <br/>";

is actually equal to:

myDiv.innerHTML = myDiv.innerHTML + "Request status: 1 (loading) <br/>";

So += means: take the value of the variable on the left, add (or when you are talking about strings, concatenate) the value on the right to it, and then load it back to the variable on the left.


Oh, and stop using w3chools, they have nothing to do with the W3C, they are nothing official, and a bad resource anyways. If you want Javascript (or CSS, HTML, DOM, etc.) reference, try MDN.

For example, they have a quite nice table on explaining what these shorthand assignment operators like += do, might have helped you a lot.

Answer:1

It is adding the text to the element called myDiv. Is like writing the text between the <div> and </div> tags.

Uses += because he wants to append the text instead of replacing it. Upon your code, it will go writing the different request statuses as they happen.

Answer:2

I'm assuming the myDiv object in your javascript code represents the <div id="myDivElement" /> in your html code.

If there was html content inside of <div id="myDivElement">....</div>, the += operator would tell javascript to append to that content instead of replace it.

Answer:3

In a canvas I created a 2d context. In that context... with a function... I'm able to create some 'circle objects'. Now, what I want, is to get the ImageData of a single circle object instead of the ...

In a canvas I created a 2d context. In that context... with a function... I'm able to create some 'circle objects'. Now, what I want, is to get the ImageData of a single circle object instead of the ...

Currently I am trying to pull videos from a youtube channel with youtube api and then using javascript to search and categorize it. I can get a search to work on an html table, but can't get it to ...

Currently I am trying to pull videos from a youtube channel with youtube api and then using javascript to search and categorize it. I can get a search to work on an html table, but can't get it to ...

  1. retrieving videos from icloud
  2. retrieving videos from iphone
  3. retrieving videos from facebook
  4. retrieving videos from snapchat
  5. retrieving videos on ipad
  6. retrieving deleted videos from android
  7. retrieving deleted videos from iphone
  8. retrieving deleted videos from samsung
  9. retrieving deleted videos from ipad
  10. retrieving deleted videos from samsung s7
  11. retrieving deleted videos from phone
  12. retrieving deleted videos from gopro
  13. retrieving deleted videos from sony handycam
  14. retrieving deleted videos from laptop
  15. retrieving deleted videos from samsung tablet
  16. retrieving deleted videos from galaxy note 4
  17. retrieving deleted videos from computer
  18. retrieving deleted videos from canon

I am using jQuery's getScript() method to load some third part js library, I am wondering whether there's a default time out value for this method. I don't really believe getScript will keep waiting ...

I am using jQuery's getScript() method to load some third part js library, I am wondering whether there's a default time out value for this method. I don't really believe getScript will keep waiting ...

I have created a simple extension for use on a clients pc to add a save image option to the context menu. Googles Chrome extension documentation, plus examples quoted on the web, leads me to believe I ...

I have created a simple extension for use on a clients pc to add a save image option to the context menu. Googles Chrome extension documentation, plus examples quoted on the web, leads me to believe I ...