Coding-Spot

You are not connected. Please login or register

Go to page : 1, 2  Next

 
 
 

add css on javascript

Message (Page 1 of 2)

#1

weeknight

weeknight
 
Senior Member

Posted August 12th 2013, 11:02 pm

 
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





#2

Nathan Adhitya

avatar
 
Advance Member

Posted August 13th 2013, 5:49 am

 
idk about the first one.. but ik about the second one
that was using the original js not using the jQuery i guess
so in jquery you can use $ or jQuery to defind the id/class/other REMEMBER : ID = # CLASS = .
example for $
Code:
$('#nathan');
and example for jquery
Code:
jQuery('#nathan');
the first one if you you to use things like .css
Code:
$('classname').css('css style name','style');
so example
Code:
$('.testing2').css('margin','10px');
then there's also a how to animate and add a class or even remove a class
to find out more about jquery and js look at w3schools.com





#3

weeknight

weeknight
 
Senior Member

Posted August 13th 2013, 11:47 am

 
Hi nathan you give me code about jQuery, i need understand about JS then jQuery.. :)
thanks for share code..

But how about my code in above?
How to add CSS in JS, please someone help me, i need learn, thanks a lot Smile





#4

weeknight

weeknight
 
Senior Member

Posted August 14th 2013, 7:59 am

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





#5

Jaques

Jaques
 
CS Staff
CS Staff

Posted August 14th 2013, 6:21 pm

 
You need only to edit here :
Code:
 text[number++] = "Random text string ."
And add a div class ,for example :

Code:
 text[number++] = "<div class="randomly">Random text string .</div>"
And now to go in your CSS Stylesheet and insert only that :

Code:
.randomly{
font-size:11pt;
font-family: Trebuchet MS;
font-style: Italic;
color: #333;
}
Change with what you want ,is solved ?





#6

weeknight

weeknight
 
Senior Member

Posted August 14th 2013, 9:13 pm

 
ok thanks jaques for answer my topic :)
but whether the code was not wrong?
I tried but it did not come out.

Code:
<script>        function text() {
                };
                text = new text();
                number = 0;
                // textArray
                text[number++] = "<div class="randomly">Real success is determined by two factors. First is faith, and second is action.</div>"
                text[number++] = "<div class="randomly">Keep going and never quit! The champion is never quit.</div>"
                text[number++] = "<div class="randomly">Make a history in your life, not just a story.</div>"
                text[number++] = "<div class="randomly">If you want to get the best, follow the best person.</div>"
                text[number++] = "<div class="randomly">Delay does not make us deserve to be success.</div>"
                // keep adding items here...
                increment = Math.floor(Math.random() * number);
                document.write(text[increment]);
                //--></script>
whats wrong? thanks a lot :D





#7

mangaka

mangaka
 
Advance Member

Posted August 15th 2013, 11:41 am

 
You can read this :P http://www.impressivewebs.com/jquery-tutorial-for-beginners/





#8

weeknight

weeknight
 
Senior Member

Posted August 15th 2013, 1:10 pm

 
Javascript not jquery lol,,, :p





#9

mangaka

mangaka
 
Advance Member

Posted August 15th 2013, 6:52 pm

 
LOL...Sorry my bad.

http://www.w3.org/wiki/Dynamic_style_-_manipulating_CSS_with_JavaScript or http://blog.cloudflare.com/combining-javascript-css-a-better-way





#10

weeknight

weeknight
 
Senior Member

Posted August 16th 2013, 6:27 pm

 
Manga@ok thanks :)

--------------

please help me bro mark, thanks a lot Smile





#11

Nathan Adhitya

avatar
 
Advance Member

Posted August 16th 2013, 7:30 pm

 
i'm not sure about this but..
where are you testing it?





#12

weeknight

weeknight
 
Senior Member

Posted August 16th 2013, 10:26 pm

 
this my forum :)
http://budokai.indonesianforum.net/

---------

ok im explain my problem  :)
hmm :)
now you can see this image,  
This text on poster
add css on javascript 7dOu62H

and when reload/refresh page, text change again
add css on javascript 7ErplEX

more details you can visit to this forum
http://duelacademy.net/forum

---------
this code for random text, (work 100% but not use css)
and now i need  my  code for javascript add some class about css
Code:
function text() {
        };
        text = new text();
        number = 0;
        // textArray
        text[number++] = "Real success is determined by two factors. First is faith, and second is action."
        text[number++] = "Keep going and never quit! The champion is never quit."
        text[number++] = "Make a history in your life, not just a story."
        text[number++] = "If you want to get the best, follow the best person."
        text[number++] = "Delay does not make us deserve to be success."
        // keep adding items here...
        increment = Math.floor(Math.random() * number);
        document.write(text[increment]);
        //-->
so can be set positions, margins, font color, font type, at least, can be set with css. :)

help me, im newbie on javascript..
im very appreciate, thanks a lot Wink





#13

Nathan Adhitya

avatar
 
Advance Member

Posted August 16th 2013, 10:44 pm

 
Ohh!
so you was adding the
Code:
<div>
with something like
Code:
<div id="">
right?
you should change the quotation mark to be ' not " anymore since you used " at the javascript


and here's an example =
Code:
text[number++] = "<div class='randomly'>Delay does not make us deserve to be success.</div>"





#14

weeknight

weeknight
 
Senior Member

Posted August 17th 2013, 10:01 am

 
yes its wrok, :)
i try in display>generalities, work
add css on javascript Dy17b1C
Code:
<script>function text() {
        };
        text = new text();
        number = 0;
        // textArray
        text[number++] = "<div class='random1'>Real success is determined by two factors.</div>"
         text[number++] = "<div class='random1'>Keep going and never quit! The champion is never quit.</div>"
        text[number++] = "<div class='random1'>Make a history in your life, not just a story.</div>"
        // keep adding items here...
        increment = Math.floor(Math.random() * number);
        document.write(text[increment]);
        //--></script>
css
Code:
.random1 {
  color: violet;
  font-family: tahoma,verdana,arial;
  font-size: 18px;
  font-weight: bold;
}
now i need put on poster my forum :)
add css on javascript XEinQnV

i done try put in
Code:
<!-- BEGIN switch_logo_center -->
 <div style="border:1px solid #141414;"><div style="height: 264px; overflow:hidden; border:3px solid #080808; background: url('http://i.imgur.com/KS899tE.png');" id="mainlogo">
                                                          <table cellspacing="0" cellpadding="0" border="0" align="center" ><tbody><tr>
                                                            <a href="/forum"><div style="height:125px; width:342px; background:url('http://i.imgur.com/7G8ePbB.png') no-repeat;" id="onlylogo"></div></a>
                                                            </tr></tbody></table>
                                                          </div></div>
                                    
       
                                       
 <!-- END switch_logo_center -->
so like this
Code:
<!-- BEGIN switch_logo_center -->
 <div style="border:1px solid #141414;"><div style="height: 264px; overflow:hidden; border:3px solid #080808; background: url('http://i.imgur.com/KS899tE.png');" id="mainlogo">
                                                          <table cellspacing="0" cellpadding="0" border="0" align="center" ><tbody><tr>
                                                            <a href="/forum"><div style="height:125px; width:342px; background:url('http://i.imgur.com/7G8ePbB.png') no-repeat;" id="onlylogo"></div></a>
                                                            </tr></tbody></table>
                                                          </div></div>
                                    

<script>function text() {
        };
        text = new text();
        number = 0;
        // textArray
        text[number++] = "<div class='random1'>Real success is determined by two factors.</div>"
         text[number++] = "<div class='random1'>Keep going and never quit! The champion is never quit.</div>"
        text[number++] = "<div class='random1'>Make a history in your life, not just a story.</div>"
        // keep adding items here...
        increment = Math.floor(Math.random() * number);
        document.write(text[increment]);
        //--></script>
<!-- END switch_logo_center -->
but doesnt work, :(
why?? can you help me? thanks Happy





#15

weeknight

weeknight
 
Senior Member

Posted August 18th 2013, 1:40 pm

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





#16

Sponsored content


 

Posted

 





Message (Page 1 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