JavaScript not replacing the img src attribute using jquery

i am replacing the img src attribute using javascript

my code is

<div class="reader" id="reader1"></div>    

    <img src="images/img_001.jpg" alt="image" id="image1"/>

</div> 

and javascript code

$("#image1").attr("src").replace("images/img_001.jpg", "images/img_002.jpg");

the src attribute is not replacing

Answer:1

You don’t need to call replace(), just set the new src:

$("#image1").attr("src", "images/img_002.jpg");
Answer:2

See http://api.jquery.com/attr/#attr2 :

$("#image1").attr("src", "images/img_002.jpg");
Answer:3

You can directly set the value of src with:

$("#image1").attr("src", "images/img_002.jpg");

http://jsfiddle.net/VFgn8/

Have a look at jQuery doc for attr() .

Answer:4

I have been working on making a form that uploads an image through ajax with php doing the upload. For some background I am having an issue where the xhr.readyState and .Status seem to run and upload....

I have been working on making a form that uploads an image through ajax with php doing the upload. For some background I am having an issue where the xhr.readyState and .Status seem to run and upload....

  1. ajax javascript with php
  2. ajax with javascript
  3. ajax with javascript example
  4. javascript ajax with parameters
  5. javascript ajax with headers
  6. ajax with javascript tutorial
  7. javascript ajax with promise
  8. javascript ajax with callback
  9. javascript ajax with json
  10. ajax with javascript or jquery
  11. javascript ajax with data
  12. javascript ajax with post
  13. javascript ajax with cookies
  14. javascript ajax with timeout
  15. ajax with javascript function
  16. javascript ajax with laravel
  17. javascript ajax with jsonp
  18. ajax with javascript html
  19. ajax javascript to php variable
  20. ajax javascript to python

This code works perfect for crome and firefox.. but error in IE8 if($('#soundcheck').is(':checked')){ //alert('checked'); var audio = document.createElement('...

This code works perfect for crome and firefox.. but error in IE8 if($('#soundcheck').is(':checked')){ //alert('checked'); var audio = document.createElement('...

  1. jquery play notification sound

Possible Duplicate: Javascript outer scope variable access I have a javascript module that looks something like below. The main issue I'm having is how to access variables in the "this" scope ...

Possible Duplicate: Javascript outer scope variable access I have a javascript module that looks something like below. The main issue I'm having is how to access variables in the "this" scope ...

  1. javascript private inner class

i can find text of an element by using this code.but i want to find a single word any where in my page if mouse hovers on that word for certain time. $(document).bind("mouseover", function (e) { ...

i can find text of an element by using this code.but i want to find a single word any where in my page if mouse hovers on that word for certain time. $(document).bind("mouseover", function (e) { ...

  1. find word under cursor vim
  2. word find under the sea
  3. vscode find word under cursor
  4. emacs find word under cursor
  5. intellij find word under cursor
  6. vi find word under cursor
  7. eclipse find word under cursor
  8. visual studio find word under cursor
  9. vim find next word under cursor
  10. search for word under cursor vim
  11. search word under cursor vim
  12. get word under cursor vim
  13. word under cursor vim