Javascript onclick for class and name -


I'm new to JavaScript and I'm sure how to do the following:

I've got a Only the CSS "class" but with the different "name" attributes, using two links incredible javascript, I need to individually separate each task. Is there any way to do this?

Example Code:

  & lt; One class = "classname" name = "link 1" & gt; Link 1 & lt; / A & gt; & Lt; One class = "classname" name = "link 2" & gt; Link 2 & lt; / A & gt; Let's say I have "this link 1" for the console when I click on link 1. And "this link is 2" when the link 2 is clicked.   

Attach an event handler to the elements, and only check the name and whatever you want

  var elems = document.querySelectorAll ('class name'); (Var i = elems.length; i--;) {ames [i] .addEventListener ('click', Fn, false); } Function fn () {if (this.name == 'link1') {console.log ('this is link 1'); } And if (this.name == 'link2') {console.log ('this link is 2'); }}   



Comments

Popular posts from this blog

Verilog Error: output or inout port "Q" must be connected to a structural net expression -

jasper reports - How to center align barcode using jasperreports and barcode4j -

c# - ASP.NET MVC - Attaching an entity of type 'MODELNAME' failed because another entity of the same type already has the same primary key value -