Jump to content
DarkxPunk

<A> Using Onclick="" Ignore Css Formatting

Recommended Posts

Whenever I use <a onclick="">on text</a> it ignores the css formatting for the <a>. Why? Is there a way around it?

Share this post


Link to post
Share on other sites

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">.

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

What's wrong with using the button tag? You can style it as you wish

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites
What's wrong with using the button tag? You can style it as you wish
I'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>

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites

I attempted to use span and the area is not clickable and does not work at all. Sorry need another idea.

Share this post


Link to post
Share on other sites

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; }

Share this post


Link to post
Share on other sites
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. Edited by DarkxPunk

Share this post


Link to post
Share on other sites
I found my problem with why span would not work.
which was?

Share this post


Link to post
Share on other sites
which was?
Simply forgot the () at the end of the JS function within the HTML. Thats why clicking did not react.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

×
×
  • Create New...