0

I have the following HTML:

<body>
  <div id="contentPane">
    ...
    ...
    <div guidedhelpid="friendsuggestions">
    ...
  </div>
</body>

I need to do some changes in guidedhelpid. For example, $(#theElem).remove()

Note: I can use jQuery upon request.

What is the best way to do it?

4

2 回答 2

3

如果您使用的是 jQuery(根据要求),那么您可以这样做$('div[guidedhelpid=friendsuggestions]')

对于纯 javascript,您可以使用此函数返回包含该属性名称的元素数组:

function getElementsByAttributeName(attr) {
    var arr_elms = document.body.getElementsByTagName("*"),
        elms_len = arr_elms.length,
        return_arr = [];

    for (var i = 0; i < elms_len; i++) {
       if(arr_elms[i].getAttribute(attr) != null){  
           return_arr.push(arr_elems[i]);
       }
    }

    return return_arr;
}
于 2013-08-04T19:13:54.743 回答
1

如果使用 Jquery,则可以通过

   var div = $('div[guidedhelpid="friendsuggestions"]');
于 2013-08-04T19:15:46.270 回答