+ 2
Please help me 😕
example code html: <h1 id="example"> Example </h1> js: var example = document.getElementById("example"); document.title= "This is my" + example; The title turns "This is my [object html]" Whats the problem?
6 Answers
+ 6
@Igoor Silver:
The 'value" attribute is valid only for <input>s elements, when they handle a "value" attribute...
For retrieving ( or setting ) the content of an element, you should use the 'innerHTML' attribute:
var example = document.getElementById("example");
alert("This is my" + example.innerHTML); /// I did it with an alert() because on code playground you cannot see the 'document.title' value :P
You can even use the 'textContent' attribut, wich return/set only textual content ( without html tags )...
+ 5
@StoffelJs:
I finally had post a question, so I can answer more accuratly to: << how can I mark a answer as the correct one >>...
The "best answer" can be marked by clicking ( hilighting ) the checkmark under the arrows for up and down vote ;)
+ 4
( you should have a "mark as best answer" button or option menu ;) )
+ 2
Try:
document.title = "This is my" + example.value;
+ 1
Each element has a few options such as font, value, name, title, ID and more. Basically document.getElementById("elementID"); Is just a way to access this information.
Therefore, if you, for example, want to get the text of an elenent you add .value.
0
Ok it works 👌👌😱✌️
Thank u visph
(How can i mark a answer as the correct one? 😬)



