#2325 document.querySelectorAll() in dom::Doc

SlimerDude Thu 7 Aug 2014

Hi,

I was just wondering what the chances would be of adding:

to dom::Doc?

It essentially does what jQuery's Sizzle does - selects DOM elements from a CSS selector - very useful! It means you don't have to use IDs for everything.

It's supported in all the browsers listed in Can I Use.

andy Thu 7 Aug 2014

Promoted to ticket #2325 and assigned to andy

Yeah we can add those

SlimerDude Thu 7 Aug 2014

Cool, while you're there, you may also want to consider:

  • document.getElementsByTagName()
  • document.getElementsByClassName()

as mentioned in JavaScript: Most Frequently Used DOM Methods.

andy Tue 19 Aug 2014

Ticket resolved in 1.0.67

New methods:

  • Win.parent
  • Win.top
  • Doc.query
  • Doc.queryAll

Changesets:

The CSS selector engine really obsoletes those tag/class name accessors, so I did not add those guys to keep the API simpler.

SlimerDude Wed 20 Aug 2014

The CSS selector engine really obsoletes those tag/class name accessors, so I did not add those guys to keep the API simpler.

That's cool. I think the new query methods will be really useful.

As an aside, I've always found it tricky to set up WebMods and pages in Wisp to deliver and run Fantom code. But with a new addition to Duvet for BedSheet it's now really easy! The code is as simple as:

@Js
class MyJavascript {
    Void greet(Str name) {
        Dialog.openInfo(Window(), "Fantom says, '${name}'")
    }
}

class IndexPage {
    @Inject HtmlInjector? injector

    Text render() {
        injector.injectFantomMethod(MyJavascript#greet, ["Hello Mum!"])
        return Text.fromHtml("<html><head></head><body></body></html>")
    }
}

See the Run Fantom Code In a Browser! article for full example code.

It even shows you how to do this (!):

Screenshot of an FWT example running in a browser

Have fun!

Login or Signup to reply.