views:

57

answers:

3

Hello! 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="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?

+2  A: 

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.

rahul
THX! ...input.myitemclass is better than .myitemclass... (like in jquery!)Another question:Thinking myitemclass is a div instead of an input. How can I change the html inside the div? (in jQuery it's like $('#id divclass').html())
Newbie
A: 

Should be faster

$("myitemid").down("input[class~=myitemclass]").value
Andris
+1  A: 

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()
tvanfosson