Bootstrap Modal was able to load another html, but I would like to specify the elements to load.

Asked 2 years ago, Updated 2 years ago, 77 views

See here to view another html

However, you cannot specify an element to import.
For example, based on the contents of the above page,

in Lab 6.html Is it possible to load only 'div class="panel-body"

?

I tried using .load in jquery, but since all the sources in html are loaded,
I can't even consider how to deal with it.
It would be very helpful if someone could let me know.
Thank you for your cooperation.

bootstrap

2022-09-30 21:25

1 Answers

If Lab6.html contains the following:

<html>
<body>
    <h1>test</h1>
    <div class="panel-body">this and that</div>
    <div>hoge</div>
</body>
</html>

This is an example of jquery extraction of div class="panel-body".
(This is an example of when div class="panel-body" is only one, if there are more than one, use .eq() to take it out.)

<html>
<head>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
    <script type="text/javascript">
        $(function(){
            $.get("lab6.html", function(data){
                varjq_obj=$($.parseHTML(data)));
                $("#data").append(jq_obj.filter("div.panel-body"));
            });
        });
    </script>
</head>
<body id="data">    
</body>
</html>


2022-09-30 21:25

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.