简体   繁体   中英

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?

Try:

element.set_attribute "readable", "0"

Or if you have a Hpricot::Elements :

elements.set "readable", "0"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM