Jump to content
Killersites Forums

Help Me with JQUERY attr please


Recommended Posts

hello, i need help with a code that i am trying to work on. It doesn't seem to work for me at all.....

 

i am using JQUERY SLIDE EFFECTS

 

and i can't seem to get this to work how i want it to.

 

Basically i want to get the image to swap back to "bear.gif" when the effect has finished.

 

Here is my code...

 

$(window).load(function() {
       $('#slider').nivoSlider();

	//polar bear menu action 
	$("#logo").toggle(function(){
		 $("#polarbear a img").attr('src','images/polarbearcub.gif');
		 $("#menu").show('slide', {direction: 'left'}, 3000); 

		 //after animation is complete i want to change polarbear image src back to images/bear.gif
		 $("#polarbear a img").attr('src','images/bear.gif');

	},function(){
		$("#polarbear a img").attr('src','images/polarbearcub.gif');
		$("#menu").hide('slide', {direction: 'left'}, 3000);
	});


   });

Link to post
Share on other sites
  • 2 months later...

I don't believe attribute is being used properly:

 

As of jQuery 1.6, the .attr() method returns undefined for attributes that have not been set. In addition, .attr() should not be used on plain objects, arrays, the window, or the document. To retrieve and change DOM properties, use the .prop() method.

 

Specially because you are using window, what about document.ready() instead.

 

 

"Launching Code on Document Ready

 

The first thing that most Javascript programmers end up doing is adding some code to their program, similar to this:

 

window.onload = function(){ alert("welcome"); }

 

Inside of which is the code that you want to run right when the page is loaded. Problematically, however, the Javascript code isn't run until all images are finished downloading (this includes banner ads). The reason for using window.onload in the first place is that the HTML 'document' isn't finished loading yet, when you first try to run your code.

 

To circumvent both problems, jQuery has a simple statement that checks the document and waits until it's ready to be manipulated, known as the ready event":

 

 

$(document).ready(function(){

// Your code here

});

 

 

 

hope that helps

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...