user1504343
user1504343

Reputation: 49

How can I place two statements on same line?

<a href="index.shtml">Home</a>

<p id="dt"></p>

<script>
document.getElementById("dt").innerHTML = "hello";
</script>

I just need both statements on the same line. This must be simple!! (but I cant do it!) Thanks

Upvotes: 0

Views: 1191

Answers (3)

khadija-djarraya
khadija-djarraya

Reputation: 25

<a href="index.shtml" style=' white-space: nowrap;'>Home</a>


<div id="dt" style='display: inline-block;'></div>

<script >
document.getElementById("dt").innerHTML = "hello";
</script>

Reference

Upvotes: 0

c0rnpuk3
c0rnpuk3

Reputation: 39

The <p> tag will create a new line by default. One way to prevent this is CSS display: inline.

<style>
 #dt {display: inline;}
</style> 

<a href="index.shtml">Home</a> 

<p id="dt"></p>

<script>
 document.getElementById("dt").innerHTML = "hello";
</script>

Upvotes: 0

p is representing a paragraph and therefore is (usually) a block element. For what you are doing, you would be better served with using an inline element like span.

Making the element inline will lead to both being displayed on the same line. If switching the tag is not an option, use css to set display:inline on the paragraph.

Upvotes: 2

Related Questions