Ask Question Forum:
Model Library:2025-02-08 Updated:A.I. model is online for auto reply question page
C
O
M
P
U
T
E
R
2
8
Show
#
ASK
RECENT
←
- Underline
- Bold
- Italic
- Indent
- Step
- Bullet
- Quote
- Cut
- Copy
- Paste
- Table
- Spelling
- Find & Replace
- Undo
- Redo
- Link
- Attach
- Clear
- Code
Below area will not be traslated by Google,you can input code or other languages
Hint:If find spelling error, You need to correct it,1 by 1 or ignore it (code area won't be checked).
X-position of the mouse cursor
Y-position of the mouse cursor
Y-position of the mouse cursor
Testcursor
caretPos
Attachment:===
Asked by grasslime
at 2024-07-30 20:35:47
Point:500 Replies:7 POST_ID:829179USER_ID:12019
Topic:
jQuery;;
i am trying to make the clicked link background color to blue and other links to white.
its not working. pl help.
its not working. pl help.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>Untitled Document</title><script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script><script>$(document).ready(function() { $( "#country,#game,#drink" ).click(function(){ $("#"+$(this)).css( "background-color", "blue" ); $("#"+$(this)).not().css( "background-color", "#fff" ); });});</script></head><body><ul> <li id="country"><a href="#">country</a></li> <li id="game"><a href="#">game</a></li> <li id="drink"><a href="#">drink</a></li></ul></body></html> 1:2:3:4:5:6:7:8:9:10:11:12:13:14:15:16:17:18:19:20:21:22:23:
Author: grasslime replied at 2024-07-31 20:28:31
thanks for additional info on .bind.
can some one provide solution using .not() ?
can some one provide solution using .not() ?
Expert: duncanb7 replied at 2024-07-31 09:10:40
You could say this method is better than the one in previous post suggested
Because every reply code I tested it on my server .
Duncan
Because every reply code I tested it on my server .
Duncan
Expert: Gary replied at 2024-07-31 09:07:57
I didn't say it was deprecated, I said it is not the recommended method and not required in this instance.
Expert: duncanb7 replied at 2024-07-31 08:12:51
Gray,
I can NOT find .bind is depreciated for all jquery versions or latest in google search or in jquery site, I just find this jquery depreicated link at http://api.jquery.com/category/deprecated/
Could you show us .bind is depreciated and not able to used in jquery latest version ?
Please advise
Duncan
I can NOT find .bind is depreciated for all jquery versions or latest in google search or in jquery site, I just find this jquery depreicated link at http://api.jquery.com/category/deprecated/
Could you show us .bind is depreciated and not able to used in jquery latest version ?
Please advise
Duncan
Expert: duncanb7 replied at 2024-07-31 07:58:12
Thanks your reminder but it works from my jquery library(not too old) , sometimes it is hard to be aware or keep track of any function is depreciated or not from the vendor in any time, I just send the idea to the author about .
if ($(this).text()=="country")$(this).css( "background-color", "blue" );
if ($(this).text()!="country")$(this).css( "background-color", "white" );
Hope you understand it.
Duncan
if ($(this).text()=="country")$(this).css( "background-color", "blue" );
if ($(this).text()!="country")$(this).css( "background-color", "white" );
Hope you understand it.
Duncan
Accepted Solution
Expert: Gary replied at 2024-07-31 07:25:33
400 points EXCELLENT
@Duncan
Stop telling people to use .bind when .on is the preferred method (and .bind may become deprecated) and it is not even needed in this situation.
@grasslime
Stop telling people to use .bind when .on is the preferred method (and .bind may become deprecated) and it is not even needed in this situation.
@grasslime
$(document).ready(function () { $("#country,#game,#drink").click(function () { $("#country,#game,#drink").css("background-color", "#fff"); $(this).css("background-color", "blue"); })}); 1:2:3:4:5:6:
Assisted Solution
Expert: duncanb7 replied at 2024-07-30 23:04:24
100 points EXCELLENT
you need to use bind() click, try this, it works, change the white color to your white color code if need
duncan
duncan
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>Untitled Document</title><script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script><script>$(document).ready(function() { $( ".tap" ).bind( "click", function() { // alert( message ); if ($(this).text()=="country")$(this).css( "background-color", "blue" ); if ($(this).text()!="country")$(this).css( "background-color", "white" );});});</script></head><body><ul> <li class="tap" id="country"><a href="#">country</a></li> <li class="tap" id="game"><a href="#">game</a></li> <li class="tap" id="drink"><a href="#">drink</a></li></ul></body></html> 1:2:3:4:5:6:7:8:9:10:11:12:13:14:15:16:17:18:19:20:21:22:23:24:25:26:27: