Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is 'disabled' a valid attribute for an anchor tag

Tags:

html

angularjs

If I have the following simple code segment:

<div ng-app="myApp">     <a ng-disabled='true' ng-click="value1=123">click me</a>     <button ng-disabled='true' ng-click="value2=123">click me</button>     =={{value1}}==     =={{value2}}== </div> 

As you can see from the fiddle : http://jsfiddle.net/basarat/czVPG/ the button is not clickable and ng-click (which is simply a jquery on('click',function(){}) ) does not execute. However it does execute for the anchor tag.

  • Is it because disabled is not a valid attribute for an anchor tag?
  • If it is why does it still trigger the dom click event when a button does not?
like image 780
basarat Avatar asked Sep 10 '13 05:09

basarat


People also ask

Can we disable anchor tag?

To disable a HTML anchor element with CSS, we can apply the pointer-events: none style. pointer-events: none will disable all click events on the anchor element. This is a great option when you only have access to class or style attributes. It can even be used to disable all the HTML links on a page.

Which are the valid HTML anchor tags?

The <a> nchor element is simply an anchor to or from some content. Originally the HTML specification allowed for named anchors ( <a name="foo"> ) and linked anchors ( <a href="#foo"> ).

Does a tag have disabled?

The <a> tag doesn't have a disabled attribute, that's just for <input> s (and <select> s and <textarea> s). To "disable" a link, you can remove its href attribute, or add a click handler that returns false.


2 Answers

Read w3c Link and the-a-element

disable is not valid with anchor tags

instead you can do it by event.preventDefault()

$('a').click(function(event){    event.preventDefault(); }); 
like image 97
Tushar Gupta - curioustushar Avatar answered Sep 18 '22 17:09

Tushar Gupta - curioustushar


Disabled is not a valid attribute for the anchor tag. Source : http://dev.w3.org/html5/html-author/#the-a-element

like image 20
basarat Avatar answered Sep 19 '22 17:09

basarat