+ 3
[SOLVED] Styling variables in JS by CSS
Example: Var a=function() { document.write("hello"); } So now I'm gonna style the text appeard in this function by css.i set it to a variable so that it could be easier to style. How should I call this variable in CSS?like for exp the elements in html can be called by id(#),class(.) but I don't know what to do with this...
13 Answers
+ 2
You can write any html text inside document.write() function and then style it using inline style or just adding an id attribute and call it from related css file as normal, like this:
JS:
Var a=function() {
document.write("<h1 id="test ">hello</h1>");
}
CSS:
#test
{
/* put any style you want */
}
+ 2
Farnaz.A you can not use javascript variables inside css, but you can change the style of an element dynamically via javascript's DOM elements, style property.
Or you can use css variables to explain this see this code
https://code.sololearn.com/Wkd7l4t629p1/?ref=app
+ 2
Example about dom
https://code.sololearn.com/WrzVk2vyWxbT/?ref=app
+ 2
Farnaz.A remove the double quot from id attribute and use single quot.
https://code.sololearn.com/W8geo1irh1Vw/?ref=app
Happy Coding!!
+ 2
Farnaz.A You are Welcome!!
+ 1
Farnaz.A You Welcome!!
+ 1
Clean<Code> tnx . that's what I needed exactly 😁
+ 1
Farnaz.A you're welcome
+ 1
great content.
+ 1
Python variables
Is it possible to assign an integer as a string variable? For example:
1 = “Hello World”
0
Matiyas tnx
0
Clean<Code> i have a problem, I set the ID for the text inside document.write but it gives me an error says missing argument after ) . Here is my attempt :
document.write("</br><p id="t1">text</p>");
0
Matiyas thank u so much 😉
Hot today
Python — File Handling
2 Votes
Help me
0 Votes
Question is write a c program to print prime numbers up to n and print the largest number in array.
1 Votes
What’s wrong?
2 Votes
Achievements on Sololearn
1 Votes
Queue & dequeued
0 Votes