0

I have a this HTML Code in a separate file and I have to add it to a another HTML page.

<!-- TAGLIO DONNA MEDIO -->                                               
<div class="form-inline divNoMargin col-md-12 def_taglioDonnaMedio noPadding ">
    <!-- TITLE -->
    <label class="col-md-5 noPaddingLeft divNoMargin defTaglioDonnaMedioTitle testoPiccolo">Taglio Donna Medio</label>

    <!--OPRZIONI PREZZO -->                                    
    <!-- SELECT 1 -->
    <div class=" col-md-8 divNoMargin  select1">
        <label class="testoPiccolo pull-left">prezzo:</label>
        <label for="" id="" class="col-md-4 pull-right testoMedio text-right prezzo defPrezzoTagliodonnaMedio">,00</label>
    </div>        

    <!-- SELECT 2 -->
    <div class=" col-md-8 noMarginLeft2 hidden select2">
        <label class="pull-left testoPiccolo">prezzo a partire da:</label>
        <label for="" id="" class="pull-right col-md-4 testoMedio text-right prezzo noMarginLeft2 defPrezzoTagliodonnaMedio">,00</label>
    </div>         

</div>

I tried using this jquery but doesn't work. Anyone

var parentDiv2 = $(document).find('.nuoviServiziReview1');
$.get( "nuoviServiziReview.html", function( data ) {
    var nuovoServizioReview = $('<div/>',{id:'Servizio'+ incremento}).append(parentDiv2);
    nuovoServizioReview.html(data);
})
5
  • You need to use .appendTo(). Commented Apr 12, 2016 at 8:24
  • I tried also appendTo but doesn't work Commented Apr 12, 2016 at 8:25
  • What exactly are you trying to do? Commented Apr 12, 2016 at 8:26
  • Assuming the HTML you're trying to load is on the same domain (otherwise CORS issues) use .load() Commented Apr 12, 2016 at 8:27
  • add this HTML code to nother page whe the a button is clicked Commented Apr 12, 2016 at 8:27

3 Answers 3

1

It is because, you are not doing anything to the DOM:

var parentDiv2 = $(document).find('.nuoviServiziReview1');
$.get( "nuoviServiziReview.html", function( data ) {
    var nuovoServizioReview = $('<div/>',{id:'Servizio'+ incremento});
    nuovoServizioReview.html(data);
    nuovoServizioReview.appendTo(parentDiv2);
})
Sign up to request clarification or add additional context in comments.

Comments

0

Have you tried load?

http://api.jquery.com/load/

Description: Load data from the server and place the returned HTML into the matched element.

$('.nuoviServiziReview1').load('nuoviServiziReview.html');

1 Comment

also load doesn't work. Yes it is in the same domain
0

append(content) appends content to the inside of every matched element. appendTo(selector) appends all of the matched elements to another specified set of elements.

Also

A.append(B) appends B to A
A.appendTo(B) appends A to B

So you need to use appendTo() instead of append() as:

var parentDiv2 = $(document).find('.nuoviServiziReview1');
$.get( "nuoviServiziReview.html", function( data ) {
    var nuovoServizioReview = $('<div/>',{id:'Servizio'+ incremento});
    nuovoServizioReview.html(data);
    nuovoServizioReview.appendTo(parentDiv2);
});

This should work :)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.