To implement one task, you need to "pull" the value from the <p> tag not using the id attribute, but using the name , but I just can't do it. Tried differently: either the error pops up, or undefined .

 alert(document.my_form.list.example_1); 
 <form name="my_form"> <ol name="list"> <li name="example_1">2*12</li> <li name="example_2">2*11</li> <li name="example_3">2*10</li> </ol> </form> 

    2 answers 2

    Use document.getElementsByName() . Read more here: http://www.w3schools.com/jsref/met_doc_getelementsbyname.asp

      As @AlexChermenin wrote above, you can get elements by name through document.getElementsByName() .

      Specifically, in your example, you can write as follows:

       alert(document.getElementsByName("example_1")[0].innerHTML); 
       <form name="my_form"> <ol name="list"> <li name="example_1">2*12</li> <li name="example_2">2*11</li> <li name="example_3">2*10</li> </ol> </form> 

      In this code snippet we get all the elements of the page with name="example_1" . Because in the example there is only one element with such an attribute, we can immediately select the first element of the array [0] and continue to perform the action. In this example, using .innerHTML took the content from the element. If there are several elements with the same attributes and the same attribute values, it is necessary to additionally carry out checks when searching an array, for example, by id , class or other attributes.

      • Thank you very much, otherwise I already started to deal with 'getElementsByName ()' and then a problem arose, you solved it;) - Mark_8