javascript finding an element with the text befor the element

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • hoxa1235
    New Member
    • Nov 2013
    • 1

    javascript finding an element with the text befor the element

    is there any methode to find an element like in this is example:
    Element <input type="text" />
    for example if i want to be able to change the value of the input after the text "Element" , is that possible , without nowing the name or the id of the input . thank's for help.
  • bomb23
    New Member
    • Nov 2013
    • 2

    #2
    hi ,
    it is possible , but you must know number of your input tags in your html document, for example:
    Code:
    <html>
    <input type="text" />
    <input type="text" />
    <input type="text" />
    </html>
    
    <script>
    var firstInput = document.getElementsByTagName('input')[0];
    </script>
    this code get you first input and if change the 0 to 1 you will have the Second input and ...
    good lock

    Comment

    • Dormilich
      Recognized Expert Expert
      • Aug 2008
      • 8694

      #3
      for example if i want to be able to change the value of the input after the text "Element" , is that possible
      no. or at least not without a fulltext search.

      HTML is a markup language that bases its information on tags, hence you have very efficient access algorithms when it comes to tags. text however is not part of any HTML structure and therefore it’s way more difficult to find an arbitrary piece of text than an arbitrary element.

      Comment

      • 9815402440
        New Member
        • Oct 2007
        • 180

        #4
        value can be changed as suggested by bomb23 but this approach is not reliable. because tag-numbers are generated on compile and this number may vary if new elements are added or deleted. you can change value by tag-number if you know the name or id of the control that lies immediately after or previous the target control. then tag-number can be calculated by adding or deducting 1 from the tag-number of control that lies after or previous the target control. literally it is impossible to change the value without knowing name or id

        Best wishes
        Manpreet Singh Dhillon

        Comment

        Working...