Load specific content from a div that is in another html file with jQuery

0

Save list! I need a help here, I have a ".html" file where I mount a list that is configured like this:

<!-- ... -->
<header>
    function Open(id) {
        console.log(id);
        var x = $("#div"+id);
        $.get("descrs/greanerydescriptions_pt.html #div_"+id, function(data) {
             $("#content").append(data);
         });
         $("#headercontainer").hide();
        return false;
    }       
</header>

<body>
<div class="container content" id="content">
</div>
<div class="container headercontent" id="headercontainer">
    <div class="card cardheader" id="_000">
    <img class="card-img-top cardimgheader" src="images/abobora.jpg" alt="Abóbora" id="imgh_000">
    <header id="hdh_000"><h2 class="title">Abóbora</h2></header>
    <div class="card-body" id="div_abobora">
    <p>Nome Popular - Abóbora</p>
    <p>Nome Científico - Cucurbita moschata Duch.</p>
    <div class="form-group" align="right">
    <a href="descrs/greanerydescriptions_pt.html#div_000" class="btn btn-primary" id="btnh_000" onclick="Open('_000')" target="_parent">Descrição e Plantio</a>
    </div>
    </div>
    </div>
    <br>
    <div class="card cardheader" id="_001">
    <img class="card-img-top cardimgheader" src="images/abobrinha.jpg" alt="Abobrinha" id="imgh_001">
    <header id="hdh_001"><h2 class="title">Abobrinha</h2></header>
    <div class="card-body" id="div_abobrinha">
    <p>Nome Popular - Abobrinha italiana, abobrinha verde, abobrinha</p
    <p>Nome Científico - Cucurbita pepo L.</p>
    <div class="form-group" align="right">
    <a href="descrs/greanerydescriptions_pt.html#div_001" class="btn btn-primary" id="btnh_001" onclick="Open('_001')" target="_parent">Descrição e Plantio</a>
    </div>
    </div>
    </div>
   <br>
</div>
<!-- ... -->
</body>

The file "greanerydescriptions_en.html" is configured like this:

<!-- ... -->
</header>
<body>
<div class="card cardcontainer" id="div_000">
<img class="card-img-top cardimgcontainer" src="../images/abobora.jpg" alt="Abóbora" id="imgc_000">
<header id="hdc_000"><h2 class="title">Abóbora</h2></header>
<div class="card-body" id="div_abobora">
<p>Nome Popular - Abóbora</p>
<p>Nome Científico - Cucurbita moschata Duch.</p>
<!-- ... -->
</div>
</div>
<br>
<!-- ... -->
<div class="card cardcontainer" id="div_001">
<img class="card-img-top cardimgcontainer" src="../images/abobrinha.jpg" alt="Abobrinha" id="imgc_001">
<header id="hdc_001"><h2 class="title">Abobrinha</h2></header>
<div class="card-body" id="div_abobrinha">
<p>Nome Popular - Abobrinha italiana, abobrinha verde, abobrinha</p>
<!-- ... -->
</div>
</div>
</body>

The code of the function Open(id) {...} is working, but it returns the whole file, and I need it to bring only the specified div that is instantiated in the event 'onclik="Open (' _ xxx '); p>

I do not know how to solve this.

Could anyone help me?

Thank you

    
asked by anonymous 17.08.2018 / 00:37

1 answer

0

Try to do this:

$("#content").append($("<div>" + data + "</div>").find("#div_"+id));
    
17.08.2018 / 11:57