Go Back   CodingForums.com > :: Client side development > JavaScript programming > JavaScript frameworks

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 09-28-2012, 06:59 PM   PM User | #1
angelali
Regular Coder

 
Join Date: Sep 2011
Posts: 310
Thanks: 23
Thanked 0 Times in 0 Posts
angelali is an unknown quantity at this point
JQuery background image change not working

Hello, I am making a mini game in JQuery. Normally, I have a DIV where it ha a background image.

The background image now will change after the user clicks on a button.

Here is my CSS codes for the DIV:

Code:
#tank #view {
	width:1000px;
	height:540px;
	background-image:url(../images/view.png);
	margin:auto;
	position:relative;
}
Here now is the JQuery codes where the background image should be changed:

Code:
$('.activate').click(function () {
	$('#tank #view').css('background-image', 'url(../images/newa.png)');
	$('#first').fadeOut();
	$(this).hide();
Well, it seems the background image is not changing. As you see in the JQuery codes, I have two other elements which should fade out and hide, both are working, except the background image is not changing...
angelali is offline   Reply With Quote
Old 09-28-2012, 07:35 PM   PM User | #2
DanInMa
Senior Coder

 
DanInMa's Avatar
 
Join Date: Nov 2010
Location: Salem,Ma
Posts: 1,307
Thanks: 12
Thanked 204 Times in 204 Posts
DanInMa is on a distinguished road
is the #view element inside of the #tank element?
__________________
- Firebug is a web developers best friend! - Learn it, Love it, use it!
- Validate your code! - JQ/JS troubleshooting
- Using jQuery with Other Libraries - Jslint for Jquery/other JS library users
DanInMa is offline   Reply With Quote
Old 09-28-2012, 08:46 PM   PM User | #3
angelali
Regular Coder

 
Join Date: Sep 2011
Posts: 310
Thanks: 23
Thanked 0 Times in 0 Posts
angelali is an unknown quantity at this point
Yes... it is inside... The CSS codes itself say all lol
angelali is offline   Reply With Quote
Old 09-28-2012, 09:42 PM   PM User | #4
VIPStephan
The fat guy next door


 
VIPStephan's Avatar
 
Join Date: Jan 2006
Location: Halle (Saale), Germany
Posts: 7,614
Thanks: 5
Thanked 865 Times in 842 Posts
VIPStephan is a jewel in the roughVIPStephan is a jewel in the roughVIPStephan is a jewel in the rough
The CSS alone says nothing. Please show us your entire HTML, ideally a link to a live example. Have you checked out the error console? Does it possibly give any hints?
__________________
Don’t click this link!
VIPStephan is offline   Reply With Quote
Old 09-29-2012, 06:34 AM   PM User | #5
angelali
Regular Coder

 
Join Date: Sep 2011
Posts: 310
Thanks: 23
Thanked 0 Times in 0 Posts
angelali is an unknown quantity at this point
Here is the HTML:

Code:
<section id="tank">
	<div id="view">
    	<p>Lorem ipsum...</p>
     </div>
</section>
angelali is offline   Reply With Quote
Old 09-29-2012, 07:42 AM   PM User | #6
VIPStephan
The fat guy next door


 
VIPStephan's Avatar
 
Join Date: Jan 2006
Location: Halle (Saale), Germany
Posts: 7,614
Thanks: 5
Thanked 865 Times in 842 Posts
VIPStephan is a jewel in the roughVIPStephan is a jewel in the roughVIPStephan is a jewel in the rough
Oh, by the way: image paths in the JS file must be relative to the HTML file. Think of it like the JS is executed in the HTML document, therefore it’s looking for any assets from that location.
__________________
Don’t click this link!
VIPStephan is offline   Reply With Quote
Users who have thanked VIPStephan for this post:
angelali (09-29-2012)
Old 09-29-2012, 08:05 AM   PM User | #7
angelali
Regular Coder

 
Join Date: Sep 2011
Posts: 310
Thanks: 23
Thanked 0 Times in 0 Posts
angelali is an unknown quantity at this point
What do you mean? It is not good my codes in JQuery? As far as I know it is like this we must do that. When I put a background color instead of a background image, it works, but for image not!
angelali is offline   Reply With Quote
Old 09-29-2012, 08:08 AM   PM User | #8
angelali
Regular Coder

 
Join Date: Sep 2011
Posts: 310
Thanks: 23
Thanked 0 Times in 0 Posts
angelali is an unknown quantity at this point
The crap is working when I remove the image from the "Images" folder. Weird! Thank you anyway... Problem solved...
angelali is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 02:38 AM.


Advertisement
Log in to turn off these ads.