By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,949 Members | 889 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,949 IT Pros & Developers. It's quick & easy.

javascript finding an element with the text befor the element

P: 1
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.
Nov 8 '13 #1
Share this Question
Share on Google+
3 Replies


P: 2
hi ,
it is possible , but you must know number of your input tags in your html document, for example:
Expand|Select|Wrap|Line Numbers
  1. <html>
  2. <input type="text" />
  3. <input type="text" />
  4. <input type="text" />
  5. </html>
  6.  
  7. <script>
  8. var firstInput = document.getElementsByTagName('input')[0];
  9. </script>
  10.  
this code get you first input and if change the 0 to 1 you will have the Second input and ...
good lock
Nov 12 '13 #2

Dormilich
Expert Mod 5K+
P: 8,639
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.
Nov 12 '13 #3

9815402440
100+
P: 180
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
Nov 12 '13 #4

Post your reply

Sign in to post your reply or Sign up for a free account.