How to generate code in div in javascript

-1

I wanted to know how to put a html code in a tag div using 'javascript

I would also like an explanation on how to redirect someone to my page if someone removes my id from the page, I have seen this before, designers create themes and put so that users do not remove credits ...

    
asked by anonymous 29.03.2016 / 20:20

3 answers

1

You can do this with jQuery: link

$(document).ready(function() {
  var elemento = $('#Creditos');
  if (elemento.length > 0) {
    elemento.text('Seu texto vai aqui');
  } else {
    window.location = 'http://github.com';
  }
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script><divid="Creditos"></div>
    
29.03.2016 / 20:41
4
document.getElementByClassName('Creditos').innerHtml('codigo html aqui');

I imagine you want it if someone copies your source code and removes the credit it identifies and redirects to your page, assuming the person is not going to remove the code that does this.

It would look something like this:

if(!document.getElementByClassName("Creditos")){
    window.location = "http://www.suapagina.com.br";
}
    
29.03.2016 / 20:32
1

Good morning, simple, you can do this:

<div id="Creditos"></div>

ai no JS:

var Teste = {

init: function(){

    var label = document.createElement('label');
    label.setAttribute("class", "classe_do_label");
    label.innerHTML = "Teste Label";

    document.getElementById('creditos').appendChild(label);
}};
window.onload = Teste.init();

In this example I created a label in JS I added a class in it and I added the text test label and inserted it into the html by JS itself.

I hope to have helped, hugs

;)

    
30.03.2016 / 14:56