Instead of using write, I decided to change to innerHTML. I want to write the variable get inside the id=one, what am I doing wrong ?

ps > thanks for everyone who as helped me up to this point, it was very appreciated. Hopefully learning another language will come easier !

Hi,
This is work:

if (document.images) {
var myimage = new Image();
myimage.src = "images/smile.gif";
}
//This get the paragraph with id = "one"
var par = document.getElementById("one");
var gt =("<h1>"+document.title+"</h1>" /*"and" "<h2>"+document.URLUnencoded+"</h2>"*/);
//This change the paragraph content
par.innerHTML = gt;

Thanks, that's how it's done :)

Member Avatar for diafol

I'm confused - what code are we talking about? If this relates to a previous thread, please include the code here or just carry on with the last thread if it is appropriate.

diafol - this is a new thread with a small question, it's not to be confused with a previous thread.

I decided to run the code, only for it not to work ?

<script type="text/javascript">
//if (document.images) {
//var myimage = new Image();
//myimage.src = "images/smile.gif";
//}
var ap=document.getElementById("one");
var gt=("<h1>"+document.title+"</h1>" /*"and" "<h2>"+document.URLUnencoded+"</h2>"*/);
ap.innerHTML = gt;

</script>

There is a p tag with an id of "one" in the html, although the Id does have text within, I doubt that matters the script should override that.

It works in JsFiddle but not my IDE program. Except I can't replace JSFiddle Title Tag :(

This works fine.

<!DOCTYPE html>
<html>
<head>
 <title>Your Title</title>
</head>
<body>

<p id="one">"Hello there"+one+"bye"</p>

 <script>
    var ap=document.getElementById("one");
    var gt=("<h1>"+document.title+"</h1>" /*"and" "<h2>"+document.URLUnencoded+"</h2>"*/);
    ap.innerHTML = gt;
 </script>

</body>
</html>

JsFiddle insists on writing the title, "JsFiddle" instead of "Your Title" ?

That because you run from JsFiddle platform.
If you run your page from your computer the title will be "Your title".

There is no way around this hiccup with JsFiddle ?

Member Avatar for diafol

This is not a hiccup - it's expected behaviour. Does it matter that jsfiddle shows its own title? The important thing is that when you run your pages outside jsfiddle, it should show your titles.

Doesn't matter. I'm just questioning the online editor !

Unless you can access the DOM of the page, you may not be able to edit the title. Once your page is loaded, it is your choice to manipulate it (including stop any scripts on the page that may keep refreshing). Have you ever tried that?

No I never tried that, not sure if Fiddle will allow that !

If it is an interface on a browser, you could run JavaScript at the end of the page (after loaded) and search for specific header tag. Then change the tag value there. However, I have no idea how much knowledge you have in JavaScript (not using any library)...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.