-
Apr 11th, 2007, 03:35 AM
#1
Dynamic CSS style not changing
In an anchor link I dont want to use the href because of "file not found" errors since its not an actual file. So Im using the onmouseover and onmouseout events of the anchor to change the style but no dice.
HTML Code:
<a onclick="AddToFavorites();"
onmouseover="style='cursor: pointer; text-decoration: none;'"
onmouseout="style='cursor: default; text-decoration: underline;'"
style="font-size: 12px; cursor: pointer; text-decoration: underline;"
...
>
Add to Favorites</a>
Any guidence?
Thanks
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum.
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it!
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6
-
Apr 11th, 2007, 04:08 AM
#2
Re: Dynamic CSS style not changing
I prefer not to use links for things that aren't actually links. Use buttons instead. Anchor elements should be reserved for actual hyperlinks to other pages.
However, if you must, there's no need to use JS events to do that. Just use the :hover pseudo-class.
css Code:
a {
text-decoration: underline;
cursor: pointer;
}
a:hover {
text-decoration: none;
}
-
Apr 11th, 2007, 04:15 AM
#3
Re: Dynamic CSS style not changing
But then I'll have to figure out the css sheet because the div already has a style css applied to it and that will mess it up.
I just wanted to simulated a link to execute the js code function.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum.
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it!
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6
-
Apr 11th, 2007, 04:17 AM
#4
Re: Dynamic CSS style not changing
Doesn't matter. Just drop that CSS in and it will force link behaviour on all anchor elements.
-
Apr 11th, 2007, 08:42 AM
#5
Ex-Super Mod'rater
Re: Dynamic CSS style not changing
Don't know if I'm missing the point but how about using an Anchor but href="#". Thats wot I normally do.
Also if your Div has a class like:
Code:
<div class="class1">Blah Blah<br />
<a href="#" class="class2" onclick="Func()">Click Here</a>
</div>
The link will have class1 applied to it but anything in class2 overrides class1. For example if class1 sets the font to 16pt and class2 sets it to 12pt.
Then Blah Blah will be 16pt
The link will be 12pt.
When your thread has been resolved please edit the original post in the thread ( )
and amend "-[RESOLVED]-" to the end of the title and change the icon to , Thank you.
When posting Code use the [VBCode]Code Here[/VBCode] tags to be able to use the code highlighting.
-
Apr 11th, 2007, 03:43 PM
#6
Re: Dynamic CSS style not changing
Sup Paul! Long time no see.
Yes, I know about the "#" as the href but cant use it as when you click it it adds the "#" to the end of the url in the addressbar.
I will try creating a secondary child css for it and see how it goes. If I cant still get it to work then I'll have to leave it for later as I need to finish the page.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum.
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it!
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6
-
Apr 11th, 2007, 04:08 PM
#7
Re: Dynamic CSS style not changing
IE6 and below doesn't support :hover element on any other element, so... this is the ugly way to make it work:
Code:
a.favorite { text-decoration : none; cursor : pointer; font-size : 12px; }
a.favorite:hover { text-decoration : underline; }
<a class="favorite" href="javascript:void(0)">Add to Favorites</a>
There are other ways to prevent the default href from working, unfortunatenaly IE doesn't understand the easiest ones (like onclick="return false" works in everything except IE, I guess).
If we go the unobstrusive standards way, there is base2 standards library by Dean Edwards that adds getElementsByClassName function into your toolbox, making it easy to find all the favorites links if there is more than one and you need to use class as identifier because of that. It also adds fixed event.preventDefault() feature for browsers in which it is broken or missing (yes, that means Internet Explorer!) which can prevent the default onclick event from happening.
Anyways, if there is only one favorite link in the document, we can use an ID. This example should work in everything except Internet Explorer, and it works in IE once you add base2 and bind it to the document as is guided at Dean Edwards' blog.
Code:
<html>
<script type="text/javascript">
window.onload = function() {
// get the favorite element
var favorite = document.getElementById('favorite');
// see if we got it
if (favorite) {
// change the function
favorite.onclick = function(e) {
// prevent default click event
// (this line raises error in IE if there is no base2)
e.preventDefault();
return false;
};
}
}
</script>
<a href="#" id="favorite">Add To Favorites</a>
</html>
-
Apr 11th, 2007, 04:46 PM
#8
Re: Dynamic CSS style not changing
Thanks Merri, some cool stuff on his blog (still reading as its long). I will probably ue the href="javascript:void(0) uglyness as I am pressed for time but will see if I can do the base2 stuff first.
Thanks
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum.
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it!
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6
-
Apr 15th, 2007, 04:18 AM
#9
Re: Dynamic CSS style not changing
RobDog, your questions make me cry.
All the buzzt
CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Apr 15th, 2007, 01:28 PM
#10
Re: Dynamic CSS style not changing
[Ralph Wiggum]Your answers make baby Jesus me cry.[/Ralph Wiggum]
No better solution(s)?
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum.
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it!
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6
-
Apr 15th, 2007, 02:08 PM
#11
Re: Dynamic CSS style not changing
I'm afraid that, in my view of the web, there are only terrible solutions to the question.
The way I see it, the whole link should be created by JavaScript in the first place. Since it has no functionality if JS is disabled, it shouldn't be there either.
All the buzzt
CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Apr 15th, 2007, 02:18 PM
#12
Re: Dynamic CSS style not changing
Other then an anchor, maybe using some other element to just give underlining and no-underlining on the events be better?
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum.
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it!
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6
-
Apr 15th, 2007, 02:52 PM
#13
Re: Dynamic CSS style not changing
Well, you can always create a separate page that adds to favorites without JavaScript, then also have a JavaScript solution.
-
Apr 15th, 2007, 03:04 PM
#14
Re: Dynamic CSS style not changing
Originally Posted by Merri
Well, you can always create a separate page that adds to favorites without JavaScript, then also have a JavaScript solution.
Erm, how would you add to favourites without JavaScript?
RobDog: no, not better. The simple existence of the text "Add to Favorites" is nonsensical if that is not possible.
All the buzzt
CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Apr 15th, 2007, 03:09 PM
#15
Re: Dynamic CSS style not changing
Do you mean browser bookmarks? Does RobDog mean those?
(I use favorites in my forum for marking favorite topics, so I have "add to favorites" link there.)
-
Apr 15th, 2007, 03:31 PM
#16
Re: Dynamic CSS style not changing
My Favorits code works well. Its an anchor for copying an inputbox's text link that is read only. When they hover over either the text "Link to this site" or the inputbox it will select the text in the box and a tooltip will come up showing that they can click it to copy to clipboard or Ctl+C to copy.
So its not really major but would be nice to have as they may not realize they can click the textbox.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum.
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it!
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6
-
Apr 15th, 2007, 09:42 PM
#17
Re: Dynamic CSS style not changing
I still maintain it should be a button, since JS or no JS it's never an actual hyperlink.
-
Apr 15th, 2007, 10:27 PM
#18
Re: Dynamic CSS style not changing
Since when did you maintain that?
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum.
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it!
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6
-
Apr 15th, 2007, 10:38 PM
#19
Re: Dynamic CSS style not changing
-
Apr 15th, 2007, 10:45 PM
#20
Re: Dynamic CSS style not changing
Ok, thats fair. But using a button is not an option as its asthetically
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum.
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it!
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6
-
Apr 15th, 2007, 11:57 PM
#21
Re: Dynamic CSS style not changing
You can style a button... to look like a link.
Nah, but they are completely customisable. If you specify border and background settings they lose their system appearance.
-
Apr 16th, 2007, 12:00 AM
#22
Re: Dynamic CSS style not changing
"Gimme c0d"
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum.
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it!
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6
-
Apr 16th, 2007, 12:07 AM
#23
Re: Dynamic CSS style not changing
http://www.w3schools.com/tags/tag_button.asp
css Code:
button {
border: 1px solid darkgreen;
/* etc. */
}
If you put a button inside a form it will default to submitting the form. If you put one on its own, it won't do anything: you need to add functionality through JS. Though, it should be added to the page through JS anyway. Use document.createElement.
-
Apr 16th, 2007, 05:31 AM
#24
Re: Dynamic CSS style not changing
I have used this to make a button/input[type=button] look like a link:
Code:
input.postlink, button.postlink {
display: inline;
padding: 0;
margin: 0;
border: none;
background: transparent;
color: blue;
text-decoration: underline;
cursor: pointer;
}
All the buzzt
CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|