How to find the unclosed div tag [closed]

2019-01-21 18:32发布

A unclosed div problem almost make me crazy. It is very difficult to track especially when the page is long and complex.

Any suggestions?

9条回答
对你真心纯属浪费
2楼-- · 2019-01-21 19:08

the World Wide Web Consortium HTML Validator is great at catching HTML errors.

查看更多
走好不送
3楼-- · 2019-01-21 19:16

As stated already, running your code through the W3C Validator is great but if your page is complex, you still may not know exactly where to find the open div.

I like using tabs to indent my code. It keeps it visually organized so that these issues are easier to find, children, siblings, parents, etc... they'll appear more obvious.

EDIT: Also, I'll use a few HTML comments to mark closing tags in the complex areas. I keep these to a minimum for neatness.

<body>

    <div>
        Main Content

        <div>
            Div #1 content

            <div>
               Child of div #1

               <div>
                   Child of child of div #1
               </div><!--// close of child of child of div #1 //-->
            </div><!--// close of child of div #1 //-->
        </div><!--// close of div #1 //-->

        <div>
            Div #2 content
        </div>

        <div>
            Div #3 content
        </div>

    </div><!--// close of Main Content div //-->

</body>
查看更多
爷、活的狠高调
4楼-- · 2019-01-21 19:22

Taking Milad's suggestion a bit further, you can break your document source down and then do another find, continuing until you find the unmatched culprit.

When you are working with many modules (using a CMS), or don't have access to the W3C tool (because you are working locally), this approach is really helpful.

查看更多
登录 后发表回答