0
Good afternoon, I’m trying to add a direct element in a div. Only that apparently the . append function, needs a div and another element. The problem is that the element that comes before is variable and my icon should not be.
Still testing it, my code didn’t work.
<script>
$(".card VI").ready(function(){
$("#creditcardZone").append("<h1>Teste</h1>");
});
</script>
HTML:
<div id="creditcardZone" class="card_list"> <label class="card EL"><input type="radio" checked="" value="EL" class="rdoCreditCards" name="CreditCardProvider" id="CreditCardProvider" displayname="ELO"><span><small>ELO</small></span></label><label class="card MC"><input type="radio" value="MC" class="rdoCreditCards" name="CreditCardProvider" id="CreditCardProvider" displayname="MasterCard"><span><small>MasterCard</small></span></label><label class="card DC"><input type="radio" value="DC" class="rdoCreditCards" name="CreditCardProvider" id="CreditCardProvider" displayname="Diners"><span><small>Diners</small></span></label><label class="card AX"><input type="radio" value="AX" class="rdoCreditCards" name="CreditCardProvider" id="CreditCardProvider" displayname="American Express"><span><small>American Express</small></span></label><label class="card VI"><input type="radio" value="VI" class="rdoCreditCards" name="CreditCardProvider" id="CreditCardProvider" displayname="Visa"><span><small>Visa</small></span></label></div>
If this function is not suitable for this case, it has some function alternative similar to this one, but that I can place an element inside a div, and not next to another element?
PS: I don’t have access to HTML, so I need to do it like this.
I put an image to illustrate. Basically I need to add a flag there "bank transfer", after I add it, I’ll turn it into pop-up so that it gives a bank data message, that’s all.
I don’t quite understand what you want, but the
append
includes in the "parent" element, at the end, after everything there is in the element. You can also useprepend
, which does the same, but inserts at the beginning, before all the other elements that are already in the "father"– Ricardo Pontual
It’s looking more like your code isn’t running because you didn’t put it inside the block
$.ready
– Wallace Maxters
It would be better to show the structure of the objects and where you want to insert to make it easier to help
– Ricardo Pontual
@As you can see in the image, I want to add an element that is not clicked along with the previous one, and that even if the previous element does not appear.
– Gabriel Salomão
But you do it in the page load or at some event?
– Alvaro Alves
@Ricardopunctual the big problem is precisely that the flags depend on another factor, so they may not appear and will only appear my icon. This is if it is in the DIV, and not associated with the previous element.
– Gabriel Salomão
Now I understand, what you need is to create a new element
– Alvaro Alves
I think I understand what you need, I’m going to create a snippet here and I’ve put it here for you to see if it’s
– Alvaro Alves
@Alvaroalves That’s right! But anyway, if you can pass me where was the error of Cod that I was trying I am grateful.. I tried to look here but it erased.
– Gabriel Salomão
here is the fragment
(function(){
 document.getElementById("creditcardZone").append('<h1>Teste</h1>');
})();
– Alvaro Alves
is that it? https://codepen.io/alvaro-alves/pen/zJzpMG?editors=1011
– Alvaro Alves
@Alvaroalves, exactly! I just need to add an image to the image in this block. Then I can put another function right there? Because the ultimate goal actually, is to click, open a pop-up, but this is another function that I’m studying.
– Gabriel Salomão
Can, just edit what you need.
– Alvaro Alves
Show! Thank you so much for your dedication!
– Gabriel Salomão
I edited my reply and included a call to an Alert, for you to check the way forward.
– Alvaro Alves