Advertise Here

Author Topic: [Tutorial] Change Text Tutorial  (Read 1858 times)

0 Members and 1 Guest are viewing this topic.

Offline Agent Moose

  • Moderator
  • *****
  • Posts: 836
  • Do not PM me for Code Support or Request
    • View Profile

  • Total Badges: 32
    Badges: (View All)
    Search Level 6 Tenth year Anniversary Nineth year Anniversary Eighth year Anniversary
[Tutorial] Change Text Tutorial
« on: June 01, 2007, 08:26:24 pm »
In this tutorial, you will learn how to change certain text.  I will be using my "Change 'Child Board' Text" as an example to help you out.

ok, first you will need to start the script with the script tags:
Code: [Select]
<script>

</script>

Now you will need to add the funtion to make the code work smoothly,
NOTE: you don't have to have this part, just makes the code load smoothly and faster.
Code: [Select]
<script>
function childboard_text(){
//Created by Agent Moose
$(function() {

});}
childboard_text();
</script>

Now that you have that done, you can start by getting the elements you need to change the text.  First you will need to find the text.
Code: [Select]
<script>
function childboard_text(){
//Created by Agent Moose
$(function() {
$("span b")
});}
childboard_text();
</script>
What I useually do is have the least ammount of tags so that the code will be smaller.  You can see that all I needed to get was a span tag and a bold tag since the text your trying to get is inside those tags.

Now you want to accually grab the text that you want to change.
Code: [Select]
<script>
function childboard_text(){
//Created by Agent Moose
$(function() {
$("span b").contains("Child Boards")
});}
childboard_text();
</script>
So now you see that since I added the contains("Child Boards") it is getting that text.
Now that you have the text, you will want to accually change the text.
Code: [Select]
<script>
function childboard_text(){
//Created by Agent Moose
$(function() {
child = "CHILDBOARD TEXT"
$("span b").contains("Child Boards").html(child);
});}
childboard_text();
</script>
I have added the .html(child) part because that is waht the new html will be, in this case, the text.  You see the word "child" in between the perenthases of HTML because that is a variable, and that is where the child = "CHILDBOARD TEXT"  comes in.  The dhild = is the accual variable that holds the content of the words taht you want to change "Child Boards" to.  That content goes to the .html(child) which makes the text change.

So basicly, if you wanted you could use this code, which is shorter, but the way I did it, makes it easyer to understand.
Code: [Select]
<script>
function childboard_text(){
//Created by Agent Moose
$(function() {
$("span b").contains("Child Boards").html("CHILDBOARD TEXT");
});}
childboard_text();
</script>

And that is all for the tutorial of how to change text.  I hope you found it usefull.
I will make a tutorial on variables later...
More tutorial soon at smcodes.smfforfree3.com
« Last Edit: April 23, 2008, 02:33:52 pm by Agent Moose »
Check out Revolution X's Brand new Code Index!

 

Related Topics

  Subject / Started by Replies Last post
3 Replies
1177 Views
Last post November 10, 2007, 06:47:57 am
by deathwilldie
5 Replies
1373 Views
Last post November 11, 2007, 01:00:06 pm
by cooldude101
7 Replies
1695 Views
Last post April 02, 2008, 12:45:23 am
by MyrtleGail
0 Replies
711 Views
Last post June 05, 2008, 04:09:31 pm
by Pancakes
3 Replies
1206 Views
Last post March 14, 2009, 12:17:55 pm
by KGB Hunter