class Hpricot::Elements
def attr key, value = nil, &blk
This example adds a #top anchor to each link.
records.attr("href") { |e| e['href'] + "#top" }
the new value of the attribute.
it belongs to. The block will pass in an element. Return from the block
Lastly, a block can be used to rewrite an attribute based on the element
(doc/"a").attr(:class => "basic", :href => "http://hackety.org/")
You may also use a Hash to set a series of attributes:
doc.search("p").attr("class", "basic")
matched elements.
Or, pass in a +key+ and +value+. This will set an attribute for all
#=> "http://hacketyhack.net/"
doc.search("a").attr("href")
attribute isn't found.
assigned to that attribute for the first elements. Or +nil+ if the
Pass in a +key+ on its own and this method will return the string value
Gets and sets attributes on all matched elements.
def attr key, value = nil, &blk if value or blk each do |el| el.set_attribute(key, value || blk[el]) end return self end if key.is_a? Hash key.each { |k,v| self.attr(k,v) } return self else return self[0].get_attribute(key) end end