Skip to main content
added 3 characters in body; edited tags
Source Link

I have some HTML DOM elements for which I need to capture click events, like a drop-down menu widget, etc. I guess we can implement in 2 ways:

<a href="javascript:void(0);" id="option1">My text</a> 

or another way is:

<span id="option2">My text 2</span> 

In the second option, of course I can add CSS property cursor:pointercursor:pointer.

All I need is to capture the click event, for which I can have the same click handler function for both the cases.

Do you think there is any reason why we would use anchor tag method  ?

The second option looks more clean. Also, the IE has a default behavior for anchor tag click events, which can have unwanted consequences, etc.

I have some HTML DOM elements for which I need to capture click events, like a drop-down menu widget, etc. I guess we can implement in 2 ways:

<a href="javascript:void(0);" id="option1">My text</a> 

or another way is:

<span id="option2">My text 2</span> 

In the second option, of course I can add CSS property cursor:pointer.

All I need is to capture the click event, for which I can have the same click handler function for both the cases.

Do you think there is any reason why we would use anchor tag method  ?

The second option looks more clean. Also, the IE has a default behavior for anchor tag click events, which can have unwanted consequences, etc.

I have some HTML DOM elements for which I need to capture click events, like a drop-down menu widget, etc. I guess we can implement in 2 ways:

<a href="javascript:void(0);" id="option1">My text</a> 

or another way is:

<span id="option2">My text 2</span> 

In the second option, of course I can add CSS property cursor:pointer.

All I need is to capture the click event, for which I can have the same click handler function for both the cases.

Do you think there is any reason why we would use anchor tag method?

The second option looks more clean. Also, the IE has a default behavior for anchor tag click events, which can have unwanted consequences, etc.

edited tags
Link
TazGPL
  • 3.7k
  • 2
  • 41
  • 60

any Any advantage of <a href="javascript:void(0);"> over <span> link text </span>

I have some html domHTML DOM elements for which I need to capture click events, like a dropdowndrop-down menu widget, etc. I guess we can implement in 2 ways:

<a href-"javascripthref="javascript:void(0);" id="option1"> My textid="option1">My <text</a> 

or another way is  :

<span id="option2"> Myid="option2">My text 2 <2</span> 

In the second option, offcourseof course I can add cssCSS property cursor:pointer.

All I need is to capture the click event, for which I can have the same click handler function for both the cases.

Do you think there is any reason why we would use anchor tag method ?

The second option looks more clean. Also, the IE has a default behavior for anchor tag click events, which can have unwanted consequences, etc.

any advantage of <a href="javascript:void(0);"> over <span> link text </span>

I have some html dom elements for which I need to capture click events, like a dropdown menu widget, etc. I guess we can implement in 2 ways:

<a href-"javascript:void(0);" id="option1"> My text </a> 

or another way is  :

<span id="option2"> My text 2 </span> 

In the second option, offcourse I can add css property cursor:pointer.

All I need is to capture the click event, for which I can have the same click handler function for both the cases.

Do you think there is any reason why we would use anchor tag method ?

The second option looks more clean. Also, the IE has a default behavior for anchor tag click events, which can have unwanted consequences, etc.

Any advantage of <a href="javascript:void(0);"> over <span> link text </span>

I have some HTML DOM elements for which I need to capture click events, like a drop-down menu widget, etc. I guess we can implement in 2 ways:

<a href="javascript:void(0);" id="option1">My text</a> 

or another way is:

<span id="option2">My text 2</span> 

In the second option, of course I can add CSS property cursor:pointer.

All I need is to capture the click event, for which I can have the same click handler function for both the cases.

Do you think there is any reason why we would use anchor tag method ?

The second option looks more clean. Also, the IE has a default behavior for anchor tag click events, which can have unwanted consequences, etc.

Source Link
sbr
  • 4.9k
  • 5
  • 46
  • 51
Loading