Как вынуть текст из DIV
Привет!
Есть html код: <td id="big_td_56"> <div class="inputContainer bigBoxStyleClass"> <img class="noButtonImageUnits switchImage" src="pictures/Units/SwordmanIcon.png"/> <div class="noButtonLabelInput">Солдат2</div> <div id="unitMax1" class="mapMaxButton hoverable"> <div class="iconbutton_left"> <div class="iconbutton_right"> <div class="iconbutton_middle"> <span class="mapMaxValue">MAX</span> </div> </div> </div> </div> <img class="permissionIcon switchImage" src="pictures/Browser/PermissionFalse_Colored.png"/> <input id="unitInput1" class="noButtonInputField unitsInput" type="text" size="10"/> <div class="noButtonInputCount unitsInputCount">999</div> </div> </td> Из него интересует эта часть <input id="unitInput1" class="noButtonInputField unitsInput" type="text" size="10"/> <div class="noButtonInputCount unitsInputCount">999</div> Вопрос: Как вынуть 999 и записать в переменную и знать что это относится или к input id="unitInput1" или <div class="noButtonLabelInput">Солдат2</div> Почему именно к ним? Потому что блоков <td id="big_td_56"> много и они с разными номерами. Буду признателен за помощь. |
что бы вынуть
var a=document.GetElementByClassName(""noButtonInputCount unitsInputCount").value в переменной a хранитса 999 а вторую часть вопроса неочень понял,может так?хотя могу тупить... var b=document.GetElementById("unitInput1"); b=a; |
value относится к input-ам
текст дива innerHTML должен вернуть |
Дело в том, что на самой странице много блоков в которых есть class="noButtonInputCount unitsInputCount". Получается нужно как то искать по двум признакам. Из уникальных есть input id="unitInput1"
Получается что нужно найти блок в котором есть input id="unitInput1" и далее найти class="noButtonInputCount unitsInputCount" - и потом как понимаю вынуть уже 999. Запускаю var a=document.GetElementByClassName(""noButtonInputCount unitsInputCount").value Выдает ошибку "Unexpected identifier" Тут точно нужно две "" ? А если с одной " то ошибка: "Object #<HTMLDocument> has no method 'GetElementByClassName'" |
value вытаскует и текст <div>.innerHTML тоже.В этом я уж точно уверен=)
|
Цитата:
|
Я нашел похожую тему http://javascript.ru/forum/events/28...iz-div%27.html
но в ней все просто - есть уникальный id от DIV, в моем случае сложнее - id от DIV это id блока, который разный постоянно. на разных страницах и блоков много. |
В firebug пишу команду и выдает вот это:
TypeError: Object #<HTMLDocument> has no method 'GetElementByClassName' get stack: function () { [native code] } message: "Object #<HTMLDocument> has no method 'GetElementByClassName'" set stack: function () { [native code] } __proto__: Error |
Цитата:
<div id='test'>text</div> <script>var text = document.getElementById('test').value; alert(text); </script> <div id='test'>text</div> <script>var text = document.getElementById('test').innerHTML; alert(text); </script> |
так попробуйте
alert(document.getElementById('unitInput1').parentNode.getElementsByClassName('noButtonInputCount unitsInputCount')[0].innerHTML); |
Часовой пояс GMT +3, время: 13:21. |