0

I’m “developing” a web site from Sharetribe (this is a website to create marketplaces). Sharetribe limited the “freedom” of a developer. We can add anything to the <head> of the website. So in the <head> I can change the CSS of the website, and this is great because I can change the appearance of the website.

What I’d like to do is to add HTML tags, like buttons, divs, etc. If I can do that, it would be great.

I believe this can’t be done, but first, I’d like to question — who knows, maybe I’m wrong.

m4n0
  • 29,823
  • 27
  • 76
  • 89

3 Answers3

0

It's a bit hacky, but you can use javascript to "insert" or "append" html to the body of the webpage through the head.

Kyle L.
  • 594
  • 4
  • 26
0

Pure JavaScript way:

var sibling = document.querySelector('.sibling');
var newSibling = document.createElement('div');

newSibling.className = 'sibling';

newSibling.innerHTML = 'Appended before the below div';

document.body.insertBefore(newSibling, sibling);
<body>

  <!-- Already Existing HTML -->
  <div class="sibling">I wish I had a sibling</div>

</body>

Quick jQuery way:

Include jQuery inside your head. Include the custom jQuery code inside <script></script> within <head>.

$(document).ready(function() {
  $('.sibling').append('<div class="sibling">Hey! I am here</div>');

  $('.child').wrap('<div class="child">You are not orphan anymore!</div>');
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

<body>

  <!-- Already Existing HTML -->
  <div class="child">I wish I had a parent</div>

  <div class="sibling">I wish I had a sibling</div>

</body>
m4n0
  • 29,823
  • 27
  • 76
  • 89
0

If you only have access to the head element, but not to the body, then you could try to use Javascript to add elements into the body. This only works if script tags are allowed and it has to be said that it is not really a good way of coding. But if it is the only way...

My idea (to make it a bit easier) : Include jQuery and add elements to the body by using the append function. So: you go to the jQuery downloads page, download the file and include it in the head tag. Now, you can access the body tag and insert some custom code like this:

$("body").append('<h1>Hi! I am a headline</h1>');