javascript - how to get value of h2 element - Stack Overflow

How can I get the content of h2 tag in Prototype framework?I tried this:alert($$('h2').value(

How can I get the content of h2 tag in Prototype framework?

I tried this:

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

but it haven't done anything.

thx,

Oded

edit: thank you for the fast and great support!

How can I get the content of h2 tag in Prototype framework?

I tried this:

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

but it haven't done anything.

thx,

Oded

edit: thank you for the fast and great support!

Share Improve this question edited Dec 27, 2011 at 17:08 Rob W 349k87 gold badges807 silver badges682 bronze badges asked Feb 1, 2011 at 20:15 Oded HarthOded Harth 4,4069 gold badges37 silver badges62 bronze badges 0
Add a ment  | 

3 Answers 3

Reset to default 3

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./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);

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744805712a4594763.html

相关推荐

  • javascript - how to get value of h2 element - Stack Overflow

    How can I get the content of h2 tag in Prototype framework?I tried this:alert($$('h2').value(

    2天前
    40

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信