Using jQuery in asp.net homepage

JQuery cannot identify tags when I use them on the main page. The following code:

<script type="text/javascript">
    $("body").append('<div id="test"><p>Hello</p></div>');
</script>

It works fine on regular pages, but when the body is on the main page, and I put the same code on the main page - nothing happens!

How can I add an ASP page to the body of a page? Is there any trick?

Any help would be greatly appreciated.

Mark.

+3
source share
1 answer

it looks like you need to wrap this in a document.ready block so that this will happen when the page is ready.

ASP.NET(. ). , , , , .

<script type="text/javascript">
    $(function() {
        $("body").append('<div id="test"><p>Hello</p></div>');
    });
</script>

<script type="text/javascript">
    $(document).ready(function() {
        $("body").append('<div id="test"><p>Hello</p></div>');
    });
</script>
+6

Source: https://habr.com/ru/post/1704298/


All Articles