Search the Community

Showing results for tags 'jquery'.

More search options

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


  • W3Schools
    • General
    • Suggestions
    • Critiques
  • HTML Forums
    • CSS
  • Browser Scripting
    • JavaScript
    • VBScript
  • Server Scripting
    • Web Servers
    • Version Control
    • SQL
    • ASP
    • PHP
    • .NET
    • ColdFusion
    • Java/JSP/J2EE
    • CGI
  • XML Forums
    • XML
    • Schema
    • Web Services
  • Multimedia
    • Multimedia
    • FLASH


  • Community Calendar




Website URL








Found 239 results

  1. Would like to know if i can use JQuery Mobile Forms as front end for my web api service. If so examples would be helpful. Thanks in advance
  2. I recently used PHP's json_encode( ) function to covert an array created with PHP into a JSON encoded object, as the conversion appeared normal, I then assigned the value to a Javascript variable using PHP's echo construct and reproduced it with a JS alert. This too, appeared normal. My difficulty arose when I tried using the jQuery .map( ) method to convert my nested Javascript object into a nested Javascript array. I received the following error message in my Console: TypeError: e is not an Object. (evaluating 't-1 in e') Am I being foolish to believe that I need a nested array when I already have a nested object? If not, is there not a routine to perform this very conversion?
  3. Please consider the following function and explain how to format the selectors for the highlighted jQuery objects. Please explain why you recommend what you do so that I need not ask the same question again further down the line. The names of the Javascript variables in question are, of course id and max. An iteration over the property-value pairs of a nested JSON object yields the following two pairs of property-value pairs for a single object: id : #letter_abstract and length : 150.. All other objects that are traversed by the iteration share the same property names -- only the values are different. The values of these two property-value pairs will be read into the function as id and max, respectively -- in effect, id = id and max = length Now, the jQuery objects in question are: $ (id textarea) -- where id is a Javascript variable corresponding to the value of the id attribute of an HTML div element, and textarea is the generic name of an HTML element. $(id span.display_count) -- where id is a Javascript variable corresponding to the value of the id attribute of the same HTML div element, and span.display_count is a generic HTML span element whose class attribute has the value of "display_count". $(id span.words_remaining) -- Same as above. Only the value of the class attribute is different. QUESTION: "How does one format the selectors properly?" function setWordContraint(id, max) { $(id textarea).on('keydown', function(e) { var words = $.trim(this.value).length ? this.value.match(/\S+/g).length : 0; if (words <= max) { $(id span.display_count).text(words); $(id span.words_remaining).text(max-words); }else{ if (e.which !== 8) e.preventDefault(); } }); }
  4. Please consider the following code and answer the question. Please do not omit your reasons for answering as you did. CODE SYNOPSIS: This handy piece of code places a constraint on the number of words that can be placed in a selected <textarea> element. In addition, it displays the current status of the selected element as one enters text. This code, less the iterative aspect, has been tested for one <textarea> element, but I wish now to expand it to include many <textarea> elements. In order to do this I created a mixed associative array (see below) whose data I use to select each <textarea> element and apply a different constraint. Although I have identified each <textarea> element by its unique id='' attribute I have used the class='' attribute to display the current status of the selected <textarea> element. My motivation for doing this latter is, of course, one of efficiency. My belief is that specific overrides general, and that the values generated by the id='' attribute will override those designated by the class='' attribute -- a designation that is common to all <textarea> elements. QUESTION: Is this sound Javascript programming logic? Or, must I change the class='' attributes to the same id='' attribute for each <textarea> element? <?php foreach($wordmax as $textarea => $arr) { $area_id = $arr['id']; $max = $arr['length']; $($area_id).on('keydown', function(e) { var words = $.trim(this.value).length ? this.value.match(/\S+/g).length : 0; if (words <= $max) { $('.display_count').text(words); $('.words_remaining').text($max-words); }else{ if (e.which !== 8) e.preventDefault(); } }); } ?> <textarea id='letter_body' name='letter_body'>...</textarea><br /> Word Count: <span class='display_count'>0</span> Words Remaining: <span class='words_remaining'>0</span> <textarea id='letter_abstract' name='letter_abstract'>...</textarea><br /> Word Count: <span class='display_count'>0</span> Words Remaining: <span class='words_remaining'>0</span> $wordmax = array( 'letter_abstract' => array ( 'id' => '#letter_abstract', 'length' => '150' ), 'letter_body' => array ( 'id' => '#letter_body', 'length' => '800' ), . . . 'student_bio' => array ( 'id' => '#student_bio', 'length' => '400' ), );
  5. Hi. I am familiar with some HTML but my knowledge in Javascript, JQuery and CSS is very limited. I have been learning from examples on the web and making my own changes. Please see the fiddle I am working on below; sorry if the full code is messy! There are a number of features I wish to implement but I am totally stumped! I have gotten as far as I think I can with the fiddle above and it would be more than appreciated if anyone can provide any help, possibly with any example code and where the code needs to go. When I make a multiple selection from the list, how do I get the results (divs) to show in order of most recent selection at the top? For example, if I multi-selected in the order Nuts, Meats, Vegetables, Fruits, how do I get the results (divs) to appear in the order Fruits, Vegetables, Meats, Nuts? At the moment they appear in the order that they are listed in the box. I would also like to ask if it is possible to keep the results (divs) showing for all the items selected even after a new search is performed and a new selection made. For example, if I search for 'F' and select 'Fruits' and then search for 'V' and select 'Vegetables', can I have both the 'Vegetables' and 'Fruits' divs showing in the results? At the moment, 'Vegetables' replaces 'Fruits'. If this is possible, would it also be possible to have the selected items in the list remain highlighted even after a new search is performed? For example, after making the above searches/selections, if I then search for 'ts', the list would show 'Fruits', 'Nuts' and 'Meats', but I would like 'Fruits' to still be highlighted and to be able to close the 'Fruits' div by de-selecting 'Fruits' from the list or clicking the Close (X) button on the 'Fruits' div itself. There are a few other things I have not been able to solve but I will refrain from posting too many questions at once. Any help would be greatly appreciated! Thank you.
  6. QUESTION: How does one manipulate jQuery in a $( document ).ready( function( ) {...}); with PHP? Is it even possible? BACKGROUND: I have created a form whose performance depends on a combination of both PHP and jQuery. Unfortunately, I cannot get the two sets of code to synchronize properly. A seasoned programmer would probably tell me to start over and use one or the other, but not both. Unfortunately, there are things that I know how to do in Javascript, but not in PHP, and vice versa. It is because of this that I have gotten myself into this mess.
  7. I've created a table that works responsively across various screen sizes, with columns appearing and collapsing as desired to suit the different devices on which it can be loaded. One issue I'm having, however, regards the `colspan` element. There are instances in which I would like to have a column stretch across an entire row. A quick search of Github has found the following piece of jQuery: $(function() { jQuery.fn.exists = function(){return this.length>0;} // Dynamic Colspan if($('[colspan="auto"]').exists()) { $.each($('[colspan="auto"]'), function( index, value ) { var table = $(this).closest('table'); // Get Table var siblings = $(this).closest('tr').find('th:visible, td:visible').not('[colspan="auto"]').length; // Count colspan siblings var numCols = table.find('tr').first().find('th:visible, td:visible').length; // Count visible columns $(this).attr('colspan', numCols.toString()-siblings); // Update colspan attribute }); } }); Source: Here is an example of my table structure: <table> <thead> <tr> <th></th> <th></th> <th></th> <th></th> <th></th> <th></th> </tr> </thead> <tbody> <tr> <td colspan="auto">Divider</td> </tr> <tr> <td></td> <td></td> <td></td> <td></td> <td></td> <td></td> </tr> </tbody> </table> As you can see, I have a row which makes use of `colspan="auto"` and works fantastically well with the jQuery source from above - automatically expanding to the full width of the row on page load. Where this breaks down, however, is in any instance where a `<td>` has been selected to be hidden in a responsive stylesheet. Instead of switching from `colspan="6"` to `colspan="5"` behind the scenes (DOM), we end up with one row where the colspan is too large. I've looked into `window.onresize`, as I believe the jQuery should run when the browser is made bigger or smaller, but am yet to have any success.
  8. <head> <script> $( document ).ready(function() { console.log( "ready!" ); $('#other').hide(); function otherTongue() { if ($('#tongue').val() == 'other_tongue') { $('#other').show(); } } }); </script> </head> <body> <form> <select name="tongue" id="tongue" size=4 onchange="otherTongue()" > <optgroup label='Oceania'> <option value=mi>Maori</option> <option value=haw>Hawaiian</option> <option value=sm>Samoan</option> </optgroup> <optgroup label='Not Listed'> <option value='other_tongue'>Other Language</option> </optgroup> </select> <input type='text' name='other' id='other' /> </form> </body> Why do I am receiving the error message: "Can't find variable otherTongue( )"?
  9. I am tryuing to click a button and then get cer tain members of a List to change their color. I would particularly like to know about using the "nth-child" property in some jquery. New File 2.html
  10. Hi, I'm trying to fake the placeholder attribute for a contact form using jQuery. To do so, I placed an input on top of a label tag (which is basically the value I want inside the input), and used jQuery to hide the label when pressing a key and show it back when the field is empty. I used the keypress and keyup events, like so: jQuery(function($){ $(".placeholder").each(function(){ var label = $(this).find("label"); var input = $(this).find("input"); […] input.keypress(function(){ label.stop().hide(); }); input.keyup(function(){ if(input.val() == ""){ label.stop().show(); } […] }); It works just as expected except if I start filling the input out with accents/diacritical signs which will just write on top of my label until I end up pressing a key that doesn't take accents. Is there any chance to fix this issue? Ideally, I would like to make my label disappear when pressing any key. Thanks for your help. Edit: just added an example here The label doesn't hide if I start filling out the input with any of the following keys ~ ^ ¨ ` ´, whether I combine them or not with a a, e, y, u, i, o or n. Otherwise, everything's fine.
  11. Hi, This link below is an example of select() method in jQuery but can someone tells me why the text is printed three times when I click the button:
  12. I have the following responsive site and i'm having an issue with the mobile nav menu: When you resize the window or load it in a mobile device, you have a menu with sub-menu items with a slide-down effect that show you the sub-menu items everytime you click on them and, if you click them again or click somewhere else, the sub-menu item will hide itself with a slide-up effect. The problem is when you resize the window again and click again the sub-menu items, they will now show and inmediately hide, like they execute the 2 steps without waiting for a second clicking. Here's the code: $(window).on('load resize', function () { if ($(window).width() >= 1000){ $("#menu-top").removeClass(); $("#menu-top").addClass("desktop"); }else{ $("#menu-top").removeClass(); $("#menu-top").addClass("touch"); $("#menu-top.touch .menu-item-has-children a").addClass("primer-boton").css('cursor','pointer'); $("#menu-top.touch .sub-menu a").removeClass(); $("#menu-top.touch .primer-boton").removeAttr("href"); $('#menu-top.touch .menu-item-has-children > .sub-menu').parent().click(function() { var submenu = $(this).children('.sub-menu'); if ( $(submenu).is(':hidden') ) { $(submenu).slideDown(200); } else { $(submenu).slideUp(900); } }); } });
  13. Hi, below, I am creating a slider. I am passing the sliding method to the click handler, but such method doesn't fire when I call it. Do you have any idea why? Thank you this.sliding = function(e) { that.slide_width = $(that.article).width(); that.slide_number = $(that.article).size(); that.max_pos = that.slide_width * (that.slide_number - 1); that.left_pos = $(that.inner).position().left; if ($(this).hasClass('article-previous') && that.left_pos < 0) { $(that.inner).css({ 'left': '+=' + that.slide_width + 'px' }); } if ($(this).hasClass('article-next') && -that.left_pos < that.max_pos) { $(that.inner).css({ 'left': '-=' + that.slide_width + 'px' }); that.animateSkills(); } }; element.find('.article-previous, .article-next').off('click').on('click', { slidingAction : this.sliding}, function(e){ e.stopImmediatePropagation;; // doesn't fire! });
  14. Hi, I am creating a portfolio website. Here I want that the testimonials will scroll horizontally automatically and will pause on hover. Guys, please give me some hints on how can I perform this action. Here is the markup and style. <!DOCTYPE html> <html> <head> <style> body { margin: 0; padding: 0; } .testimonials-container::-webkit-scrollbar { display: none; .testimonials-wrapper { max-width: 100%; height: 450px; border: 1px solid lightgrey; background: linear-gradient(#000000, #777474); padding-left: 25px; padding-right: 25px; position: relative; } .testimonials-quote { width: 100%; text-align: center; padding-bottom: 20px; color: white; } .testimonials-container { width: 100%; height: 100%; text-align: center; display: flex; margin: 0; padding: 0; padding-bottom: 20px; overflow: scroll; } .testimonials-item { min-width: 230.99px; max-width: 230px; height: 70%; background-color: white; margin-right: 20px; margin-left: 20px; color: black; -webkit-transition: 0.5s ease-in-out; -moz-transition: 0.5s ease-in-out; -ms-transition: 0.5s ease-in-out; -o-transition: 0.5s ease-in-out; transition: 0.5s ease-in-out; } .testimonials-item:last-child { margin-right: 0; } .testimonials-item:first-child { margin-left: 0; } .testimonials-image { width: 124px; border-radius: 50%; padding-top: 20px; } .testimonials-image img { width: 150px; height: 150px; border-radius: 50%; margin-left: 30%; } .testimonials-prev, .testimonials-next { position: absolute; top: 50%; padding: 10px 5px; font-size: 25px; color: white; cursor: pointer; z-index: 5; } .testimonials-prev { left: 0; border-radius: 0 3px 3px 0; } .testimonials-next { right: 0; border-radius: 3px 0 0 3px; } .testimonials-prev:hover, .testimonials-next:hover { background-color: white; color: black; } </style> </head> <body> <div class= "testimonials-wrapper"> <div class= "testimonials-quote"> <h1>What Others Say About Us</h1> </div> <div class= "testimonials-container"> <div class= "testimonials-item"> <div class= "testimonials-image"> <img src= "images/for%20use/tiger.jpg"/> </div> <div class= "testimonialists-name"> <h3>Rahim</h3> </div> <div class= "testimonial">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam accumsan sed leo eget malesuada.</div> </div> <div class= "testimonials-item"> <div class= "testimonials-image"> <img src= "images/for%20use/tiger.jpg"/> </div> <div class= "testimonialists-name"> <h3>Karim</h3> </div> <div class= "testimonial">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam accumsan sed leo eget malesuada.</div> </div> <div class= "testimonials-item"> <div class= "testimonials-image"> <img src= "images/for%20use/tiger.jpg"/> </div> <div class= "testimonialists-name"> <h3>Abdullah</h3> </div> <div class= "testimonial">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam accumsan sed leo eget malesuada.</div> </div> <div class= "testimonials-item"> <div class= "testimonials-image"> <img src= "images/for%20use/tiger.jpg"/> </div> <div class= "testimonialists-name"> <h3>Yasir</h3> </div> <div class= "testimonial">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam accumsan sed leo eget malesuada.</div> </div> <div class= "testimonials-item"> <div class= "testimonials-image"> <img src= "images/for%20use/tiger.jpg"/> </div> <div class= "testimonialists-name"> <h3>Mahmudullah</h3> </div> <div class= "testimonial">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam accumsan sed leo eget malesuada.</div> </div> <div class= "testimonials-item"> <div class= "testimonials-image"> <img src= "images/for%20use/tiger.jpg"/> </div> <div class= "testimonialists-name"> <h3>Riad</h3> </div> <div class= "testimonial">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam accumsan sed leo eget malesuada.</div> </div> <div class= "testimonials-item"> <div class= "testimonials-image"> <img src= "images/for%20use/tiger.jpg"/> </div> <div class= "testimonialists-name"> <h3>Shohan</h3> </div> <div class= "testimonial">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam accumsan sed leo eget malesuada.</div> </div> <div class= "testimonials-item"> <div class= "testimonials-image"> <img src= "images/for%20use/tiger.jpg"/> </div> <div class= "testimonialists-name"> <h3>Shohan</h3> </div> <div class= "testimonial">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam accumsan sed leo eget malesuada.</div> </div> </div> <span class= "testimonials-prev">❰</span> <span class= "testimonials-next">❱</span> </div> <script src= "jquery-3.1.1.min.js"></script> <script> var x = 270; $(document).ready(function() { $(".testimonials-next").click(function() { $(".testimonials-container").scrollLeft(x += 270); }); $(".testimonials-prev").click(function() { $(".testimonials-container").scrollLeft(x -= 270); }); }); </script> </body> </html> Waiting for your great hints. Thank you in advance.
  15. Hello. Let's Say That I Have Two Sites,The First One Is , And The Second One Is: , The First Site index's File Got A <div> Element With id="one" , And The Second Site index's File Got A <div> Element With id="two" ,The Question Is: How Can I Load div#one Contents Inside div#two ? I Don't Want To Use Frames. I've Read About jQuery load() Method On W3schools , But It Doesn't Seems To Give An Example About My Case. Sorry For The Prolongation.
  16. Hello In this Wordpress theme the nav menu changes when you scroll-down the page. At the begining is transparent and big, but then it gets smaller and white. How can i do that myself?
  17. Hi all, I'd like to make a responsive navigation bar with a drop down menu using jQuery but I'm having some difficulties getting it work properly. I've just started learning jQuery so my knowledges in this language are very limited for the moment. I know there is a tutorial precisely for that on w3school but I followed this tutorial on YouTube as the result is closer to what I would like to end up with. Besides, the code looks easier to me. What I'm trying to do is basically the same thing but without using an external <div> for the menu bar, which I would like to include in the list elements. To do so, I hid all the list elements using a max-height to 0 except for the "menu" one, then I toggleClassed all the list elements but the "menu" one so they get the new declaration max-height= 3em. Unfortunately, the menu doesn't drop down when clicking on the "menu" bar. Any help? Thanks. Here is the .html <!doctype html> <html lang="en"> <head> <meta charset="UTF-8"> <link rel="stylesheet" href="responsiveMenu2.css" /> <script src=""></script> <title>Test</title> </head> <body> <header> <h2>responsive navigation (mobile first)</h2> <nav> <ul> <li class="menu" id="menu"><a href="#">menu</a></li> <li class=""><a href="#">home</a></li> <li class=""><a href="#">galleries</a></li> <li class=""><a href="#">news</a></li> <li class=""><a href="#">about</a></li> <li class=""><a href="#">contact</a></li> </ul> </nav> </header> <section> <article> Sed maximum est in amicitia parem esse inferiori. Saepe enim excellentiae quaedam sunt, qualis erat Scipionis in nostro, ut ita dicam, grege. Numquam se ille Philo, numquam Rupilio, numquam Mummio anteposuit, numquam inferioris ordinis amicis, Q. vero Maximum fratrem, egregium virum omnino, sibi nequaquam parem, quod is anteibat aetate, tamquam superiorem colebat suosque omnes per se posse esse ampliores volebat. Inter haec Orfitus praefecti potestate regebat urbem aeternam ultra modum delatae dignitatis sese efferens insolenter, vir quidem prudens et forensium negotiorum oppido gnarus, sed splendore liberalium doctrinarum minus quam nobilem decuerat institutus, quo administrante seditiones sunt concitatae graves ob inopiam vini: huius avidis usibus vulgus intentum ad motus asperos excitatur et crebros. Apud has gentes, quarum exordiens initium ab Assyriis ad Nili cataractas porrigitur et confinia Blemmyarum, omnes pari sorte sunt bellatores seminudi coloratis sagulis pube tenus amicti, equorum adiumento pernicium graciliumque camelorum per diversa se raptantes, in tranquillis vel turbidis rebus: nec eorum quisquam aliquando stivam adprehendit vel arborem colit aut arva subigendo quaeritat victum, sed errant semper per spatia longe lateque distenta sine lare sine sedibus fixis aut legibus: nec idem perferunt diutius caelum aut tractus unius soli illis umquam placet. </article> </section> <script> $(".menu").on("click", function(){ $("nav ul li").not(".menu").toggleClass("showing"); }); </script> </body> </html> And the .css *{ box-sizing: border-box; } html{ width: 100%; min-height: 100%; } body{ height: 100%; margin: 0; padding: 0; text-align: center; } header{ background-color: #00795f; width: 100%; padding: 40px 0 0 0; color: white; text-transform: capitalize; } nav{ margin-top: 40px; width: 100%; background-color: #43a286; text-transform: capitalize; } nav ul{ list-style-type: none; padding: 0; margin: 0; } nav ul li:not(#menu){ max-height: 0; -webkit-transition: max-height 0.4s; -moz-transition: max-height 0.4s; -ms-transition: max-height 0.4s; -o-transition: max-height 0.4s; transition: max-height 0.4s; } nav ul li a{ display: block; width: 100%; line-height: 3em; text-decoration: none; color: white; } nav ul li a:hover{ background-color: #399077; } section{ line-height: 1.5em; font-size: 0.9em; padding: 0; width: 100%; } article{ text-align: justify; padding: 5% 4%; } #menu{ background-color: #005c48; cursor: pointer; } .showing{ height: 3em; } @media screen and (min-width: 680px){ #menu{ display: none; } nav{ height: 3em; } nav ul li{ display: inline-block; margin: 0 1%; } nav ul li a{ padding: 0 20px; line-height: 3em; } section{ max-width: 900px; margin: 0 auto; } }
  18. Hi i am new for the PHP, i had the experienced before to do a login system page but what i want it is HTML and PHP file to separate i dont want PHP with HTML together to 1 file , cause professional people will more likely to use 2 file rather than 1 file easy to maintain and edit how to use the external PHP file coding without re-design whole page cause normally what i tested before was link or turn to other new page and result will come out but the design was totally gone so have any ways and suggestion to do that ... in the end, im sorry i not well in english and my knowledge of PHP still quite new , thanks you so much
  19. HI i trying to create a website of forum textarea editor are necessary too for recommendation which editor are best for textarea such as summernote, wysihtml5 .... and how is work to store the data/value/text with styling effect in mysql database ? Thanks all of you
  20. HI i trying to create a website of forum textarea editor are necessary too for recommendation which editor are best for textarea such as summernote, wysihtml5 .... and how is work to store the data/value/text in mysql database ? Thanks all of you
  21. HI, i have no good enough of the knowledge about the CSS design, i try to making the effect like Facebook, when mouse enter the people name will pop-up a small box , displaying like the people name,profile image,background image , and other 3 button in footer. i try to made it but still fail .... i dont have idea how to make a picture in-between the background image and some simple description. is not mistaken been using the CSS change the profile image position to absolute, and i guess the z-index also need higher of number .... but those of the design ... i not design similar like the facebook....or else other webpage same as the effect but the profile image show in center instead on the left side .... have any one can make a example or sample to teaching me how to do that ... thanks all for you help and in the end ...sorry for my english are not very well, i hope you understand what i mean Thanks
  22. <div data-role="page" data-theme="b"> <div data-role="main" id="index"> <a href="#settings" data-rel="popup">Show Settings</a> </div> <div data-role="popup" id="settings" data-theme="b"> <select data-native-menu="false"> <option value="1">1</option> <option value="2">2</option> </select> </div> </div>
  23. HI i trying to create a website of forum textarea editor are necessary too for recommendation which editor are best for textarea such as summernote, wysihtml5 .... and how is work to store the data/value/text in mysql database ? Thanks all of you
  24. HI there, first i apology my english not too well, hope you may understand what i mean ,Thanks Im try to using the Bootstrap one of the function is popover similar like tooltips, but i facing the problem For example : <div id="all"> <div id="a" class="circle_ball" data-user-id="2">●</div> <div id="b" class="circle_ball" data-user-id="1">●</div> </div> and my Jquery code is : $('#all').on('mouseenter','div',function(){ $(this).popover({ title: 'Jun Hoo', content: $(this).attr('data-user-id'), trigger:'hover', html:true }); }); but the result on the code will showing delay and at least need to hover the target more than 2 time ... any ways to figure out? thanks you so much i found ways to solve the delay speed, but will keep popover the content when mouse pointer hover the first popover body the ways is add one more code --- $('#all').popover({title: 'Loading', content: '...',selector: 'div',trigger:'hover',html:true}); Thanks for helping
  25. This Code Isn't Working: <script src=""></script> <script> $(document).ready(function(){ $("#area").animate({ backgroundImage:"url('image2.png')" },2000); }); </script> <style> #area { width:100%; height:600px; background-image:url("image2.png"); } </style> <div id="area"></div>