Cómo eliminar "href" con Jquery?


<a id="a$id" onclick="check($id,1)" href="javascript:void(0)"  class="black">Qualify</a>

Después de eliminar "href", ¿todavía se puede hacer clic en" Calificar"?

 45
Author: Steven, 2009-11-06

4 answers

Su pregunta de título y su ejemplo son completamente diferentes. Comenzaré respondiendo la pregunta del título:

$("a").removeAttr("href");

Y en cuanto a no requerir un href, la forma generalmente aceptada de hacer esto es:

<a href"#" onclick="doWork(); return false;">link</a>

El retorno falso es necesario para que el href no vaya a ninguna parte.

 94
Author: Langdon,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2009-11-06 14:56:58

Si quieres que tu ancla todavía parezca ser clicable:

$("a").removeAttr("href").css("cursor","pointer");

Y si desea eliminar el href de solo anclajes con ciertos atributos (por ejemplo, aquellos que solo tienen una marca de hash como el href - esto puede ser útil en asp.net)

$("a[href='#']").removeAttr("href").css("cursor","pointer");
 20
Author: Brad Parks,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2011-02-18 19:18:52

Si elimina el atributo href, el ancla no será enfocable y se verá como un texto simple, pero aún podrá hacer clic.

 8
Author: CMS,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2009-11-06 14:58:13

Si desea eliminar el href, cambiar el cursor y también evitar hacer clic en él, esto debería funcionar:

$("a").attr('href', '').css({'cursor': 'pointer', 'pointer-events' : 'none'});

 8
Author: bryceadams,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2015-09-09 06:16:12