Selecting elements without jQuery

后端 未结 3 1991
南笙
南笙 2020-12-03 03:00

I guess this will be voted down, as it doesn\'t contain enough jQuery, but here it goes :)

What is the most effective way to get the element(s) returned by the jQuer

3条回答
  •  悲&欢浪女
    2020-12-03 03:31

    Here is an example

    var getElements = function(tagName, attribute, value, callback) {
      var tags = window.document.getElementsByTagName(tagName);
      for (var i=0; i < tags.length; i++) {
        var tag = tags[i];
        if (tag.getAttribute(attribute) == value) {
          callback(tag);
        }
      };
    };
    
    getElements("a", "title", "PHP power player at Hettema & Bergsten. Click to learn more.", function(tag) {
      console.log(tag);
    });
    

提交回复
热议问题