Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    Regular Coder
    Join Date
    Jun 2012
    Posts
    137
    Thanks
    1
    Thanked 1 Time in 1 Post

    Can I use jQuery to replace an image

    Hello,

    As the title says I am trying to replace an image on the page with another image. It appears to be working but I believe that the old image is still there. Is there a better way to do this? Should I remove the old image before I add the new one?

    Code:
    $(".bannerImage").css('background-image','url("course_assets/banner_grey.png")');
    Code:
    .bannerImage{
    	background:url('../course_assets/banner.png')no-repeat;
    	height: 88px;
    	width: 100%;
    }

  • #2
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,633
    Thanks
    0
    Thanked 649 Times in 639 Posts
    If that's the only script on your page then a better way would be to forget about jQuery and use a single JavaScript statement in place of the entire library.
    Stephen
    Learn Modern JavaScript - http://javascriptexample.net/
    Helping others to solve their computer problem at http://www.felgall.com/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •