How can I get href bindings when I click on it using javascript? I have done the following:
function myFunc() { } window.onclick = myFunc;
But how to expand the function to respond only to clicks on anchors and get href?
function linkClick (e) { alert (e.target.href); } links = document.getElementsByTagName ('a'); for (i = 0; i <links.length; i ++) links [i] .addEventListener ('click', linkClick, false);
document.onclick . . JavaScript , Prototype jQuery, :
document.onclick
$$('a').invoke('observe', 'click', function(a){ myFunc(a); });
JS, getElementsByTagName (. Delan new answer).
getElementsByTagName
, onclick . - javascript, jQuery Prototype - .
, :
var myFunc = function(target) { var href = target.href; // ... your function code that can now see the href of the calling anchor }
JQuery
$('a').click(function(){ myFunc(this); });
Protype: . Kau-Boy
function myFunc(link) { alert(link.href); return false; // return false if you don't want to actually navigate to that link } <a href onclick="return myFunc(link)">something</a>
Source: https://habr.com/ru/post/1749562/More articles:Архитектуры веб-приложений и серверов приложений? - pythonHighlight color - objective-cHow to comment on jspx page - javaHow can I read only the first row from an Excel file using OleDbDataAdapter? - c #How to find checked rows in YUI DataTable? - yuiinternal implementation of database queries - databaseProcessing "No cells were found." Error in Excel - c #Zend Routing :: How can I send all requests coming to the application-> IndexController to the application-> module-> store-> IndexController - phpКак вы программным образом нажимаете кнопку панели инструментов с помощью AppleScript? - buttonHow to search and replace part of a row in all columns in all tables in sql database - sqlAll Articles