Using Div for onclick? is that good. What is the right way?

<button type="button" onclick="displayResult()">
        Insert new row</button>

but I want to do is,

<div onclick="displayResult()"> Insert new row</div>

The function do fire ok.  Is div a right way to do onclick on a text? I do not want a look of a button

/* css */ {
cursor: pointer;
text-decoration: underline;
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Dave BaldwinFixer of ProblemsCommented:
Nothing wrong with using 'onclick' on any element that will accept it including a 'div'.  You may want to add instructions that tell the users what needs to be done if it does not look like something to click on.
Julian HansenCommented:
The function do fire ok.  Is div a right way to do onclick on a text? I do not want a look of a button
You can drive your car with your feet if you want to - does not mean it is a good idea.

Making a <div> behave like a button because you don't like the way the button looks - well it will work but it is like the example above. That is what CSS is for - use a <button> <input> or <a> and style it to look the way you want it to - would be the generally accepted practice.

So to answer your question

Using Div for onclick? is that good. What is the right way?

It will work - but no it is not considered the right way to do it in most situations. Styling a button or an anchor would be the most common approach.
goodkAuthor Commented:
so can we style the button to look like a <a href ?
Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

Julian HansenCommented:
Yes - here is some sample code (working link here)
<!doctype html>
<style type="text/css">
.my-styled-button {
  border: 0;
  padding: 0;
  margin: 0;
  background: none;
.my-styled-button:hover {
  text-decoration: underline;
  cursor: pointer;
<button class="my-styled-button">Click Me</button>

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
goodkAuthor Commented:
thank you
Julian HansenCommented:
You are welcome.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.