1

Can someone please explain how to add a custom attribute to an HTML tag using Ruby with Hpricot gem?

I have a tag that looks like this:

<div class="test" id="tag1" style="">

and I want to add a custom integer attribute called 'Readable=0' so it looks like this:

<div class="test" id="tag1" style="" readable=0>

Is this possible?

4

1 回答 1

4

Try:

element.set_attribute "readable", "0"

Or if you have a Hpricot::Elements:

elements.set "readable", "0"
于 2010-08-09T02:38:05.973 回答