dpigera
dpigera

Reputation: 3369

hpricot add attribute to a HTML tag?

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?

Upvotes: 1

Views: 547

Answers (1)

jtbandes
jtbandes

Reputation: 118691

Try:

element.set_attribute "readable", "0"

Or if you have a Hpricot::Elements:

elements.set "readable", "0"

Upvotes: 4

Related Questions