Simple Machine Codes
April 20, 2024, 04:15:43 am
Welcome, Guest. Please login or register.

Login with username, password and session length
News: Welcome to SMC, the best place for your SMF For Free Codes
 
  Home Help Search Arcade Gallery Affiliates Code Index Staff List Calendar Members Login Register  

Changing Text

Pages: [1]   Go Down
  Print  
Author Topic: Changing Text  (Read 876 times)
0 Members and 1 Guest are viewing this topic.
Agent Moose
Administrator

Offline Offline

Gender: Male
Posts: 2,672



View Profile WWW
« on: June 01, 2007, 08:25:13 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:
<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:
<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:
<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:
<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:
<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:
<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...
Report Spam   Logged

Share on Facebook Share on Twitter

Frost
Members

Offline Offline

Posts: 30


View Profile
« Reply #1 on: July 21, 2007, 08:39:47 am »

Does this mean, by following this tut, enables you to change ANY type of text?
Report Spam   Logged
Agent Moose
Administrator

Offline Offline

Gender: Male
Posts: 2,672



View Profile WWW
« Reply #2 on: July 21, 2007, 09:42:24 am »

Bascily, if you do it right, yes.
Report Spam   Logged

Celebrus
Artificially Conscious
Administrator

Offline Offline

Gender: Male
Posts: 1,337


aka Omikron


View Profile WWW
« Reply #3 on: July 25, 2007, 05:00:34 am »

Ahem. This will replace all the text within the tag. I tried to use this method for a spoiler tag code, and I messed up 2 forums. vikhyatstestforum.smfforfree3.com and vikhyatstesrforum2.smfforfree3.com
Report Spam   Logged

Agent Moose
Administrator

Offline Offline

Gender: Male
Posts: 2,672



View Profile WWW
« Reply #4 on: July 25, 2007, 01:35:53 pm »

That is the thing with Jquery, it will replace anything that is within the tag, unlike javascript.  Javascript will replace parts taht you want it to replace.
Report Spam   Logged

Pages: [1]   Go Up
  Print  
 
Jump to:  

Powered by EzPortal
Bookmark this site! | Upgrade This Forum
SMF For Free - Create your own Forum

Powered by SMF | SMF © 2016, Simple Machines
Privacy Policy