0

How to force browser reload single element of the page ('src' in my case, or 'div', no matter)? Using this code:

$("div#imgAppendHere").html("<img id=\"img\" src=\"/photos/" + recipe.id + ".png\" height=\"60px\"/>");

It changes page source, but not reload changed element. How to do it? Thanks in advance.

5
  • So what is the problem exactly? The code should add an image to the element when that code is executed. Is the image supposed to be changing on the server and it is not picking up the new image? Commented Sep 8, 2016 at 0:13
  • 1
    If you mean make it reload a resource at the same url that has changed, ie a new image was generated, just add a unique query parameter at the end of the src url, like recipe.jpg?_=148858838 Commented Sep 8, 2016 at 0:16
  • It does, source of page changes, but view of page stays as was, not reload changed element Commented Sep 8, 2016 at 0:17
  • 1
    Still have no clue what you mean "the source of page changes". Maybe you should show more code. A smaller example that shows the problem. Commented Sep 8, 2016 at 0:39
  • html page changes after script executed, but image on the page stays same as was before executing script Commented Sep 8, 2016 at 0:41

1 Answer 1

1

Patrick Evans, you right, that hack is works. So my code is:

var someRandQuery = "?" + (Math.random()*100000);
$("#imgAppendHere").html("<img id=\"img\" src=\"/photos/" + recipeId + ".png" + someRandQuery + "\" height=\"60px\"/>");
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.