Javascript-форум (https://javascript.ru/forum/)
-   Общие вопросы Javascript (https://javascript.ru/forum/misc/)
-   -   Как вынуть текст из DIV (https://javascript.ru/forum/misc/37406-kak-vynut-tekst-iz-div.html)

MOZG 18.04.2013 16:36

Как вынуть текст из 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"> много и они с разными номерами.

Буду признателен за помощь.

Vasy 18.04.2013 16:42

что бы вынуть
var a=document.GetElementByClassName(""noButtonInputCount unitsInputCount").value

в переменной a хранитса 999
а вторую часть вопроса неочень понял,может так?хотя могу тупить...
var b=document.GetElementById("unitInput1");
b=a;

animhotep 18.04.2013 16:53

value относится к input-ам
текст дива innerHTML должен вернуть

MOZG 18.04.2013 16:57

Дело в том, что на самой странице много блоков в которых есть 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'"

Vasy 18.04.2013 16:58

value вытаскует и текст <div>.innerHTML тоже.В этом я уж точно уверен=)

Vasy 18.04.2013 16:59

Цитата:

Сообщение от MOZG (Сообщение 246931)
var a=document.GetElementByClassName('noButtonInputCount unitsInputCount').value

ну конешно же одна.И я немного ошибся скобка одинарная.Пробуй innerHTML юзать тогда.я хз.Использую у себя в прогах везде value ничево не ругаетса

MOZG 18.04.2013 17:01

Я нашел похожую тему http://javascript.ru/forum/events/28...iz-div%27.html

но в ней все просто - есть уникальный id от DIV, в моем случае сложнее - id от DIV это id блока, который разный постоянно. на разных страницах и блоков много.

MOZG 18.04.2013 17:03

В 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

animhotep 18.04.2013 17:20

Цитата:

Сообщение от Vasy (Сообщение 246933)
value вытаскует и текст <div>.innerHTML тоже.В этом я уж точно уверен=)

точно - точно?)

<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>

vadim5june 18.04.2013 17:26

так попробуйте
alert(document.getElementById('unitInput1').parentNode.getElementsByClassName('noButtonInputCount unitsInputCount')[0].innerHTML);


Часовой пояс GMT +3, время: 13:21.