Coding-Spot

You are not connected. Please login or register

Go to page : Previous  1, 2

 
 
 

add css on javascript

Message (Page 2 of 2)

#1

weeknight

weeknight
 
Senior Member

Posted August 12th 2013, 11:02 pm

 
First topic message reminder :

hello bro mark, i want to learn Smile
how to merge javascript code with css?

i need  my  code for javascript add some class about css
example this code
Code:
       function text() {
        };
        text = new text();
        number = 0;
        // textArray
        text[number++] = "Random text string 1."
        text[number++] = "Random text string 2."
        text[number++] = "Random text string 3."
        text[number++] = "Random text string 4."
        text[number++] = "Random text string 5."
        // keep adding items here...
        increment = Math.floor(Math.random() * number);
        document.write(text[increment]);
        //-->
i need that code add some class about css, so can edit margin, font size, font color, pading and etc about css.

and i have this code to.
Code:
document.write("<style type='text/css'>body {CSS inside}</style>");
but I don't understand how that could be made ​​in a single code.
please teach me about javascript, mainly about merging the code. :)

i need you help me again, thanks a lot bro mark,  :D



Last edited by weeknight on August 13th 2013, 1:16 pm; edited 1 time in total





#16

Nathan Adhitya

avatar
 
Advance Member

Posted August 18th 2013, 7:48 pm

 
if you want to put it on a specified div use Jquery it's the only way like so you kill the random1 at the texts div then..
so you would use like
$('.random1').html(text[increment]);
then add the DIV somewhere at overall header and put the javascripts in the javascript section and tick all






#17

weeknight

weeknight
 
Senior Member

Posted August 18th 2013, 7:57 pm

 
Ok i will try, now im waiting bro mark, to solved my prob, thanks :)





#18

weeknight

weeknight
 
Senior Member

Posted August 19th 2013, 7:38 pm

 
24 hours to bump.
please help me bro mark, thanks :)





#19

weeknight

weeknight
 
Senior Member

Posted August 20th 2013, 8:53 pm

 
24 hours to bump.
please help me bro mark, thanks ._.





#20

Nathan Adhitya

avatar
 
Advance Member

Posted August 21st 2013, 8:17 pm

 
can i remake the script usin jQuery?





#21

weeknight

weeknight
 
Senior Member

Posted August 22nd 2013, 12:12 am

 
Yes you can try nathan, i will wait :)

I need that code can be used in overall header, i think jquery can solved this problem :)

BUMP!





#22

weeknight

weeknight
 
Senior Member

Posted August 23rd 2013, 1:06 am

 
24 hours to BUMP!

Please help me bro mark, thanks a lot.





#23

Nathan Adhitya

avatar
 
Advance Member

Posted August 23rd 2013, 6:14 am

 
try this

Code:

// Empty Function
function text() {
};

// Texts
text = new text();
number = 0;
// Add Random Texts Here
text[number++] = "Random text string 1."
text[number++] = "Random text string 2."
text[number++] = "Random text string 3."
text[number++] = "Random text string 4."
text[number++] = "Random text string 5."
// Add Random Texts UP Here

// Math Count
increment = Math.floor(Math.random() * number);

// Div Class /name / attribute
var randomid = '.random1';


// Functions () DO NOT CHANGE
if($){
   $(randomid).html(text[increment]);   
}else if(jQuery){
   jQuery(randomid).html(text[increment]);
}
else{
   document.write(text[increment]);
}
just edit the var randomid = 'random1';
to your css attribute like
var randomid = '#nathan';
btw i setted if it supports $ it will execute with $ or else if jquery suported jquery will be executed or else if nothing supports original javascript will be executed





#24

weeknight

weeknight
 
Senior Member

Posted August 23rd 2013, 5:19 pm

 
still failed, btw thanks nathan for help :) im really appreciate





#25

Nathan Adhitya

avatar
 
Advance Member

Posted August 24th 2013, 6:36 pm

 
show me your scripts changes





#26

mangaka

mangaka
 
Advance Member

Posted September 7th 2013, 5:13 pm

 
Hope this works,but...

Well,try to make a div on the js.It's looks like this:

Code:
text[number++] = "<div class="yourClass">Random text string 1.</div>"
Then,make a JQuery like this:

Code:
$("yourClass").css("color","red");
});
I will try to searching the whole Google for some info.




Blah. Edited this.

So, you just need to do this :

Code:
text.style.margin = marginvalue;
text.style.whatshere = whatshere

Or rather

Code:
var classtostyle = data.getElementsByTagName('text');
classtostyle.style.stuff = stuffies;

Sounds like that.





#27

Sponsored content


 

Posted

 





Message (Page 2 of 2)

Permissions in this forum:
You cannot reply to topics in this forum

In total there is 0 user online :: 0 Registered, 0 Hidden and 0 Guests

Users browsing this forum: None