Get All Elements in an HTML document with a specific CSS Class

前端 未结 10 922
时光取名叫无心
时光取名叫无心 2020-12-01 04:10

What\'s the best way to get an array of all elements in an html document with a specific CSS class using javascript?

No javascript frameworks like jQuery allowed her

10条回答
  •  青春惊慌失措
    2020-12-01 04:44

    @shog9, @user28742, @bdukes - I'm doing some custom development in SharePoint for a modular thing (custom field definition) I hope can be re-used across many sites.

    Since I can't know ahead of time if any given SharePoint site will have jQuery or any other library available to it --- I still need to write things in raw javascript so I can have a degree of confidence that the functionality I'm trying to achieve will stand on it's own.

    Thanks Dmitri for your particular implementation. Short enough for my purposes.

    In other recent efforts, I had to modify a e-commerce store (of my client's choosing) and some of my attempts to get jQuery rigged into it actually conflicted with whatever custom libraries they had previously rigged. I could have been persistent, and banged out a way to implement jQuery into their proprietary system.. or.. even more quickly.. just write some good ol' fashioned javascript.

    Libaries ARE NOT ALWAYS THE BEST ANSWER!!!!!!!!!!!!!!!!

    (and I love jQuery more than my grandmother)

提交回复
热议问题