How to Insert HTML Code within Javascript?

Asked

Viewed 3,875 times

-1

I have this code, I’d like to know if it’s correct the way it is?

Javascript code:

function texto(){
    if(SONome == 'Windows 10 x32'){
    window.location.href = 
'http://teccitystore.com.br/downloads/eCHEF_Install.exe';
      var a_ = '<a class="wsite-button wsite-button-small wsite-button-
highlight"></a>';
      document.html(a);
    } else if(SONome == 'Windows 10 x64'){
      window.location.href="http://teccitystore.com.br/downloads/eCHEF_Install_x64.exe
";
      var a_ = '<a class="wsite-button wsite-button-small wsite-button-
highlight"></a>';
      document.html(a);
    }

Html code:

<a class="wsite-button-inner"  ng-disabled="boxes.email" id="Win32" 
name="Win32" onclick="texto()">
Windows x32
</a>
  • Wouldn’t it be better to give the person the option to choose whether to install the 32bit or 64bit? This is because there are many situations where even most operating systems being 64bit and yet the user prefer to use 32bit (x86).

  • I agree with your point of view @Guilhermenascimento but I have a superior who asked as chosen above, I can not go against understand..

  • 1

    Yes I understand Alis, I still think that for almost everything it is possible to present arguments and even examples of large sites that do it, however returning to its problem, could tell me what function this is document.html()? It was you who created it, it is not standard I believe, where exactly you intend to inject the link <a class="wsite-button wsite-button-small wsite-button-&#xA;highlight"></a> on the page? PS: it was not I who denied the question.

  • in this part had asked help to a friend, but it did not solve much, look, on the page just when it is loaded is informed by another function like your Windows, and it was for this function ai take the value of the windows of the person who is in "Sonome", and divide between the two possible cases. If it is Wx64 would call the download file,and the button class to leave it blue. It should happen more or less in both cases.I will inject in the html code, in the part I posted, this was expected when calling the function that contained it

  • Then the only need is to start the download automatically by clicking on <a class="wsite-button-inner", correct? Then what is the use of <a class="wsite-button wsite-button-small wsite-button- highlight"> and <a class="wsite-button wsite-button-small wsite-button-&#xA;highlight"></a>? Because if they have no use I will suggest some changes to your code. Please explain exactly what you want your code to do.

  • Basically: If the variable is a case, it is to start the download. Main objective

Show 1 more comment

1 answer

1


You can use the property in the innnerHTML element = or += and enter the html code

  • could explain in more detail if possible?

  • So if you want to add for example a gift element <a> in a certain id I will demonstrate . Document.getElementById("main-content"). innerHTML += "<a class="wsite-button wsite-button-small wsite-button- Highlight"></a>"; this will add what you already had before and + this new content of html to the main-content tag, this is just an example. I prefer jQuery where you can do this faster, for example instead of looking for elementbyid makes only $('#main-content"). html("<a class="wsite-button wsite-button-small wsite-button- Highlight"></a>");, but this will be with you.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.