Find element without tag ID and Name

Asked

Viewed 1,426 times

0

Expensive,

I need to locate the element that does not contain id and name in HTML.

Below is the HTML example

    <button type="button" class="btn btn-primary ng-scope" data-ng-if="novo2()" data-ng-click="novo()" clickonce="">
                Criar Protocolo
   </button>
  • Try to find by the class class="btn btn-primary ng-scope" or by the type type="button" and if the Value is equal to Criar Protocolo

3 answers

1

You can also use it to find the element by the name of the css class

   var x = document.getElementsByClassName("btn");

If you are using jQuery becomes even easier and faster, because you have to put discretion in the search for the element.

var Elm = $('button[class*="btn"]')

The code says: find every button element that contains a "btn class";

If you want to learn more about Jquery Selector link

0

Try to locate by the element’s Xpath. Usually this is the easiest way when you don’t have a unique identifier .

0

Well, I don’t understand why not create an id or a name, but in any case:

document.getElementsByTagName('button')

With this you will get a list with all the "<"button">" of the program, so you can find by indexing:

document.getElementsByTagName('button')[0]

Browser other questions tagged

You are not signed in. Login or sign up in order to post.