Skip to main content
Code Review

Return to Answer

replaced http://stackoverflow.com/ with https://stackoverflow.com/
Source Link

I'm not too familiar with JS, so just three generic notes:

  1. It seems to me that the elements[i].attributes.length > 0 check is unnecessary because the statements inside the following for loop won't if elements[i].attributes.length is zero.

  2. Consider creating local variables for elements[i] and elements[i].attributes. It would remove some duplication.

    for (var i = 0; i < elements.length; i++) {
     var currentElement = elements[i];
     var currentAttributes = currentElement.attributes;
     for (var x = 0; x < currentAttributes.length; x++) {
     if (currentAttributes[x].name === attrib) {
     foundelements.push(currentElement);
     }
     }
    }
    
  3. It might be easier with jQuery: find element by attribute find element by attribute.

I'm not too familiar with JS, so just three generic notes:

  1. It seems to me that the elements[i].attributes.length > 0 check is unnecessary because the statements inside the following for loop won't if elements[i].attributes.length is zero.

  2. Consider creating local variables for elements[i] and elements[i].attributes. It would remove some duplication.

    for (var i = 0; i < elements.length; i++) {
     var currentElement = elements[i];
     var currentAttributes = currentElement.attributes;
     for (var x = 0; x < currentAttributes.length; x++) {
     if (currentAttributes[x].name === attrib) {
     foundelements.push(currentElement);
     }
     }
    }
    
  3. It might be easier with jQuery: find element by attribute.

I'm not too familiar with JS, so just three generic notes:

  1. It seems to me that the elements[i].attributes.length > 0 check is unnecessary because the statements inside the following for loop won't if elements[i].attributes.length is zero.

  2. Consider creating local variables for elements[i] and elements[i].attributes. It would remove some duplication.

    for (var i = 0; i < elements.length; i++) {
     var currentElement = elements[i];
     var currentAttributes = currentElement.attributes;
     for (var x = 0; x < currentAttributes.length; x++) {
     if (currentAttributes[x].name === attrib) {
     foundelements.push(currentElement);
     }
     }
    }
    
  3. It might be easier with jQuery: find element by attribute.

Source Link
palacsint
  • 30.3k
  • 9
  • 82
  • 157

I'm not too familiar with JS, so just three generic notes:

  1. It seems to me that the elements[i].attributes.length > 0 check is unnecessary because the statements inside the following for loop won't if elements[i].attributes.length is zero.

  2. Consider creating local variables for elements[i] and elements[i].attributes. It would remove some duplication.

    for (var i = 0; i < elements.length; i++) {
     var currentElement = elements[i];
     var currentAttributes = currentElement.attributes;
     for (var x = 0; x < currentAttributes.length; x++) {
     if (currentAttributes[x].name === attrib) {
     foundelements.push(currentElement);
     }
     }
    }
    
  3. It might be easier with jQuery: find element by attribute.

default

AltStyle によって変換されたページ (->オリジナル) /