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)

avatar
 
Senior Member

Posted on Mon Aug 12, 2013 4: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 Tue Aug 13, 2013 6:16 am; edited 1 time in total



View user profile


avatar
 
Advance Member

Posted on Sun Aug 18, 2013 12: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




View user profile


avatar
 
Senior Member

Posted on Sun Aug 18, 2013 12:57 pm

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



View user profile


avatar
 
Senior Member

Posted on Mon Aug 19, 2013 12:38 pm

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



View user profile


avatar
 
Senior Member

Posted on Tue Aug 20, 2013 1:53 pm

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



View user profile


avatar
 
Advance Member

Posted on Wed Aug 21, 2013 1:17 pm

 
can i remake the script usin jQuery?



View user profile


avatar
 
Senior Member

Posted on Wed Aug 21, 2013 5:12 pm

 
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!



View user profile


avatar
 
Senior Member

Posted on Thu Aug 22, 2013 6:06 pm

 
24 hours to BUMP!

Please help me bro mark, thanks a lot.



View user profile


avatar
 
Advance Member

Posted on Thu Aug 22, 2013 11:14 pm

 
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



View user profile


avatar
 
Senior Member

Posted on Fri Aug 23, 2013 10:19 am

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



View user profile


avatar
 
Advance Member

Posted on Sat Aug 24, 2013 11:36 am

 
show me your scripts changes



View user profile


avatar
 
Advance Member

Posted on Sat Sep 07, 2013 10:13 am

 
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.



View user profile


#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