DarkxPunk Posted December 19, 2011 Share Posted December 19, 2011 Whenever I use <a onclick="">on text</a> it ignores the css formatting for the <a>. Why? Is there a way around it? Link to comment Share on other sites More sharing options...
Ingolme Posted December 19, 2011 Share Posted December 19, 2011 The default link formatting (blue with underline) is given to links that have the HREF attribute. Give your link an HREF attribute and it will style normally. If your link doesn't require an HREF attribute then maybe there's another element that's better for the task, like <button> or <input type="button">. Link to comment Share on other sites More sharing options...
DarkxPunk Posted December 19, 2011 Author Share Posted December 19, 2011 There must be a way other than button or input. I simply want a plain text button that caries out a javascript function but has a css style. Link to comment Share on other sites More sharing options...
TheGallery Posted December 19, 2011 Share Posted December 19, 2011 What's wrong with using the button tag? You can style it as you wish Link to comment Share on other sites More sharing options...
Ingolme Posted December 19, 2011 Share Posted December 19, 2011 You can use any element you like. But you're going to have to set the color to blue and give it an underline with CSS yourself. a { color: blue; text-decoration: underline;} The browser only styles, by default, the links that have an HREF attribute. If it doesn't then you have to style it manually. Link to comment Share on other sites More sharing options...
thescientist Posted December 19, 2011 Share Posted December 19, 2011 What's wrong with using the button tag? You can style it as you wishI'm not sure, but it may be block level by default. There must be a way other than button or input. I simply want a plain text button that caries out a javascript function but has a css style.use <span> Link to comment Share on other sites More sharing options...
DarkxPunk Posted December 20, 2011 Author Share Posted December 20, 2011 You can use any element you like. But you're going to have to set the color to blue and give it an underline with CSS yourself.a { color: blue; text-decoration: underline;} The browser only styles, by default, the links that have an HREF attribute. If it doesn't then you have to style it manually. Okay so if I understand correctly. In CSS if I style <a> it will only come into effect if it follows as so <a href=""></a>; otherwise it ignores the styling. Now just my opinion but, that is stupid. If I style <a> it should style <a onclick=""> and any other combination, not only <a href="">. use <span> That is a good idea... Truly never thought of it. What's wrong with using the button tag? You can style it as you wish Now with using the button tag, I am not too familiar with it, nor do I know how to style it to simply display as text and not a 'button'. I am assuming you can't do it though... To summarize. I will go with the span idea! Peace Link to comment Share on other sites More sharing options...
DarkxPunk Posted December 20, 2011 Author Share Posted December 20, 2011 I attempted to use span and the area is not clickable and does not work at all. Sorry need another idea. Link to comment Share on other sites More sharing options...
Ingolme Posted December 20, 2011 Share Posted December 20, 2011 No, I didn't say styles are ignored for the <a> element. I'm saying that the browser's default style (underlined and blue) only applies to links with an href attribute. Any element is clickable, it just won't have the same cursor as the <a> element does. This can be changed by setting the CSS of the element:span { cursor: pointer; } Link to comment Share on other sites More sharing options...
DarkxPunk Posted December 20, 2011 Author Share Posted December 20, 2011 No, I didn't say styles are ignored for the <a> element. I'm saying that the browser's default style (underlined and blue) only applies to links with an href attribute. Any element is clickable, it just won't have the same cursor as the <a> element does. This can be changed by setting the CSS of the element:span { cursor: pointer; } I found my problem with why span would not work. I will continue to get everything working. Thanks for all the help everyone. Link to comment Share on other sites More sharing options...
thescientist Posted December 20, 2011 Share Posted December 20, 2011 I found my problem with why span would not work. which was? Link to comment Share on other sites More sharing options...
DarkxPunk Posted December 20, 2011 Author Share Posted December 20, 2011 which was? Simply forgot the () at the end of the JS function within the HTML. Thats why clicking did not react. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.