开发者

how to get value of h2 element

开发者 https://www.devze.com 2023-02-08 12:05 出处:网络
How can I get the content of h2 tag in Pr开发者_高级运维ototype framework? I tried this: alert($$(\'h2\').value());

How can I get the content of h2 tag in Pr开发者_高级运维ototype framework?

I tried this:

alert($$('h2').value());

but it haven't done anything.

thx,

Oded

edit: thank you for the fast and great support!


The $$ returns an Array.

I you only want the first <h2>, then access it at index 0.

alert($$('h2')[0].innerHTML);

Or you can iterate over the Array using prototypejs' .each() method.

$$('h2').each(function(el,i) {
    alert(el.innerHTML);
});


$$(el) creates an array. You need to iterate over each value, or if you just want the first h2, then use .first()

alert($$('h2').first().value());

Check out the API http://globalmoxie.com/bm~doc/prototype-160-api.pdf


Shouldnt you use .html(). jQuery is using this, i think prototype would use something similar.

Try this: alert($('h2').innerHTML);

0

精彩评论

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