1
Je veux supprimer une liste d'attributs d'événements dom de html? comment faire ça? comme:comment supprimer l'attribut d'événement de html using Hpricot?
before = "<div onclick="abc" >abc</div>"
after = clean_it(before) // after => "<div>abc</div>"
DOM_EVENT_TO_BE_REMOVE = "onclick|ondblclick|onerror|onfocus|onkeydown" // i want to remove these events
// i want to do it like this
def clean_it(html)
doc = Hpricot(html)
doc.search(DOM_EVENT_TO_BE_REMOVE).remove_attribute(DOM_EVENT_TO_BE_REMOVE)
doc.to_s
end
merci.
'DOM_EVENT_TO_BE_REMOVE =% p [onclick ondblclick onerror onfocus onkeydown]' pourrait être un peu plus propre . – kejadlen
merci beaucoup .. – www
doit-il être doc.search ("* [@ onclick]")? Je pense que la syntaxe css a besoin d'un type d'élément avant de trouver les attributs. Le caractère générique permet de rechercher tous les éléments. – Lukas