+ 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?

30th Apr 2017, 7:22 PM
StoffelJs
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 )...
1st May 2017, 6:06 AM
visph
visph - avatar
+ 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 ;)
8th May 2017, 4:18 PM
visph
visph - avatar
+ 4
( you should have a "mark as best answer" button or option menu ;) )
1st May 2017, 7:32 AM
visph
visph - avatar
+ 2
Try: document.title = "This is my" + example.value;
30th Apr 2017, 7:40 PM
Igoor Silver
Igoor Silver - avatar
+ 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.
30th Apr 2017, 7:45 PM
Eldar Bakerman
0
Ok it works 👌👌😱✌️ Thank u visph (How can i mark a answer as the correct one? 😬)
1st May 2017, 7:28 AM
StoffelJs