search

Home  >  Q&A  >  body text

javascript - Why are the margin values ​​different between using native js to get the body and using jquery to get the body?

console.log(document.getElementsByTagName("body")[0].style.margin)  空
        console.log($("body").css("margin"))  8px
怪我咯怪我咯2811 days ago910

reply all(2)I'll reply

  • 黄舟

    黄舟2017-07-05 10:44:07

    You can try to get width and the like, and the result will be ''

    Because XXX.style.XXX extracts industry attributes

    Because what you set through XXX.style.XXX is also an inline attribute, so you can get it this time

    Then how to take out the attributes set with css

    getComputedStyle(element).margin

    reply
    0
  • 迷茫

    迷茫2017-07-05 10:44:07

    The two obtained tags <body> are the same, but the first attribute is overwritten and is empty, and the second one is not overwritten and is 8px.

    reply
    0
  • Cancelreply