开发者

Prototype - Element with styleclass in element with an id?

开发者 https://www.devze.com 2022-12-16 04:02 出处:网络
First of all: I\'m new to Prototype JS Framework! Until now I worked with jQuery. In jQuery I am able to get an element by coding:

First of all: I'm new to Prototype JS Framework! Until now I worked with jQuery. In jQuery I am able to get an element by coding:

$('#myitemid .myitemclass').val()

html:

<div id="myitemid">
    <input type="text" class="notmyclass" />
    <input type="开发者_JS百科text" class="myitemclass" />
    <input type="text" class="notmyclass" />
</div>

But how to do this in prototype? I tried to code:

$('myitemid .myitemclass').value

but this won't work. Can U help me plz?


Use $$ which returns all elements in the document that match the provided CSS selectors.

var elemValue = $$('#myitemid input.myitemclass')[0].getValue();

Also input.myitemclass is better than .myitemclass because it restricts search to input elements with class name .myitemclass.


If you want to get the named element myitemid, simply use $('myitemid'). This is equivalent to $('#myitemid') or document.getElementById('myitemid'). Your case is more complex, since you want to select a child of a named element. In that case you want to first find the named element, then use a selector on it's children.

$('myitemid').select('input.myitemclass')

Then, to access it's value (since it's a form element), you can add .getValue().

$('myitemid').select('input.myitemclass').getValue()


Should be faster

$("myitemid").down("input[class~=myitemclass]").value
0

精彩评论

暂无评论...
验证码 换一张
取 消