Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

JavaScript Forum


You are currently viewing our JavaScript Forum as a guest. Please register to participate.
Login



Reply
Changing the src on an input type="image" using jquery
Old 01-14-2009, 01:13 PM Changing the src on an input type="image" using jquery
tuestunim's Avatar
Experienced Talker

Posts: 41
Name: Scott Brown
Location: Huddersfield, UK
Trades: 0
Hi,

Here's one for you. I've had a go at this already but I'm crap at JS.

I've got a site where I cannot edit the HTML. I'm quite good with CSS and jQuery helps with all the other stuff I need to control. However, there's a:

Code:
<input type="image" src="blah/blah.gif" />
This has no class, no id. The only way to target this is using the cascade and input[type="image"] (and Dean Edwards IE8 script so IE can see it).

My question is, how can I target this in jQuery to change the image (or better still, change it from an image entirely so I can build a sensible proper button)?

I look forward to some creative or well tested solutions

Ta,

Scott.
tuestunim is offline
Reply With Quote
View Public Profile Visit tuestunim's homepage!
 
 
Register now for full access!
Old 01-14-2009, 01:28 PM Re: Changing the src on an input type="image" using jquery
wayfarer07's Avatar
Poo on You

Latest Blog Post:
Introducing WowWindow
Posts: 3,985
Name: Abel Mohler
Location: Asheville, North Carolina USA
Trades: 0
Code:
$(document).ready(function() {
     $('input[type="image"]').attr("src", "/whatever");
});
Remember, jQuery knows most of the CSS that your browsers don't.
__________________
Join me on
Please login or register to view this content. Registration is FREE

Last edited by wayfarer07; 01-14-2009 at 01:31 PM..
wayfarer07 is offline
Reply With Quote
View Public Profile Visit wayfarer07's homepage!
 
Old 01-15-2009, 01:09 PM Re: Changing the src on an input type="image" using jquery
tuestunim's Avatar
Experienced Talker

Posts: 41
Name: Scott Brown
Location: Huddersfield, UK
Trades: 0
Hi, thanks for your help.

I've created an image, uploaded it, referenced it using your example and added it to the head area of my page. No luck. If you get a minute, can you have a look at the page to let me know where I'm going wrong on this one? 999 Gifts.

Also, would your example affect all input type="image" on the page? I'd like to change each of them individually if possible.

Cheers,

Scott.
tuestunim is offline
Reply With Quote
View Public Profile Visit tuestunim's homepage!
 
Old 01-15-2009, 01:44 PM Re: Changing the src on an input type="image" using jquery
wayfarer07's Avatar
Poo on You

Latest Blog Post:
Introducing WowWindow
Posts: 3,985
Name: Abel Mohler
Location: Asheville, North Carolina USA
Trades: 0
jQuery doesn't work by itself, you need to define it somewhere by linking to it. You have not. Link to it before any other scripts that may need it. I usually use Google's hosted version like this:
HTML Code:
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.2.6/jquery.min.js"></script>
Yes, the way I wrote it would affect all of the inputs with a type of "image". To target different ones, just use more specific CSS rules inside your jQuery selector. Like I said before, jQuery knows CSS, including advanced CSS3 selectors like nth-child() which aren't even supported by really good browsers.
__________________
Join me on
Please login or register to view this content. Registration is FREE
wayfarer07 is offline
Reply With Quote
View Public Profile Visit wayfarer07's homepage!
 
Old 01-16-2009, 05:25 AM Re: Changing the src on an input type="image" using jquery
tuestunim's Avatar
Experienced Talker

Posts: 41
Name: Scott Brown
Location: Huddersfield, UK
Trades: 0
Sorry! I'm working on 3 or 4 sites at the moment, all of which use jquery and have it cheerfully sat in the head section. I hadn't done it yet with this one but assumed I had. Please excuse me!

What's even more annoying is that what I tried originally bears a striking resemblance to what you suggested so I might have even solved a JavaScript problem by myself for once!

Thanks a lot for your help.
tuestunim is offline
Reply With Quote
View Public Profile Visit tuestunim's homepage!
 
Reply     « Reply to Changing the src on an input type="image" using jquery
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.28001 seconds with 12 queries