Welcome Guest ( Log In | Register )

Outline · [ Standard ] · Linear+

 jQuery

views
     
TSmumeichan
post Oct 30 2009, 09:27 PM, updated 17y ago

Member
*******
Senior Member
4,152 posts

Joined: May 2005
I cant seem to get jQuery to work. I've read all kinds of tutorials on the net and used some simple examples but no matter what, the codes dont seem to work. They dont work is Dreamweaver's Live View nor do they load in FF 3.5. Is there something I have to install to get jQuery to work? Is my code simply wrong?

Here is the code I tried out
CODE
<script type="text/javascript" src="http://jqueryjs.googlecode.com/files/jquery-1.3.2.js">
<script type="text/javascript">
       $(function() {
  S(."normalname") .text() .clone(). prependTo("p100");
  });
</script>


I've added "p100" on my own and that shows up fine.

I noticed that the .text() and.clone() is fade when I input them in Dreamweaver

This post has been edited by mumeichan: Oct 30 2009, 09:49 PM
sunsuron
post Oct 30 2009, 10:38 PM

Regular
******
Senior Member
1,334 posts

Joined: Nov 2004



CODE

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>

<meta http-equiv="Content-Type" content="text/html;charset=utf-8">
<title>mumeichan</title>

</head>
<body>

<p class="normalname">Hello</p>
<p class="normalname">World</p>

<div id="bla"></div>


<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
<script type="text/javascript">

//$('#bla').html($('.normalname').text()); // get only the text and put them inside the DIV
$('.normalname').clone().prependTo('#bla'); // duplicate all element with the class 'normalname' and put them inside the DIV

</script>
</body>
</html>

TSmumeichan
post Oct 31 2009, 08:31 AM

Member
*******
Senior Member
4,152 posts

Joined: May 2005
Thanks, it works if I use it exactly as you wrote it.

However when i try it on some thread in lowyat, it doesn't work. I'm trying to see if I can collect all the usernames on a page and send them, to some paragraph right below.

This post has been edited by mumeichan: Oct 31 2009, 08:58 AM
sunsuron
post Oct 31 2009, 01:11 PM

Regular
******
Senior Member
1,334 posts

Joined: Nov 2004



If you need web scraping script, it will require mo lines of codes. Why do you need to gather all the username?
TSmumeichan
post Oct 31 2009, 04:01 PM

Member
*******
Senior Member
4,152 posts

Joined: May 2005
QUOTE(sunsuron @ Oct 31 2009, 01:11 PM)
If you need web scraping script, it will require mo lines of codes. Why do you need to gather all the username?
*
Have you played epicmafia before? If you haven't, Epicmafia is a site at www.epicmafia.com that allows you to play 'mafia' online with other players from around the world.

In a mafia game, you will be assigned to a random role, say Cop and depending on certain choices you and other players make, you will get a 'report'.

I want to write a greasemonkey script that will

1. Gather the name of the other players playing with me and send them to a list/menu on the page which I can add on my own.
2. Create other dynamic content from the list of names.

Before two days ago, I knew nothing about web designing, html, css, java, ajax and whatnot. Since I do photoshop and got myself the who CS4 suite since I'm a student, I thought hey Dreamweaver is supposed to be pretty nifty, it can do anything and well after two days I realized this need some pretty tough javascript.

Using Firebug and DOM inspector, I have identified all the ids, classes and tags, xpaths of the data I need to pull using jquery. The problem is, I can't get jQuery to work on the page as I want it to. when I create a simple test page, the jQuery scripts work fine, but when I insert them into the page they do nothing.

Another problem is I can't use any server-side stuff like php, sql etc cause that would be hacking and cheating at the same time. It has to be strictly client-side.
sunsuron
post Oct 31 2009, 10:33 PM

Regular
******
Senior Member
1,334 posts

Joined: Nov 2004



With GM, this is very easy. The only reason it will failed is because there is nothing returned by your jQuery selector. I did a quick test with GM version 0.8 on this very page and it return what I expect.

1. copy paste the jQuery core library into your GM script.
2. copy paste code below
» Click to show Spoiler - click again to hide... «


The code above will try to scan all occurrence of 'span.normalname a' which translates 'Find all <span> with have the class value of normalname and <a> as their child'. I will get an alert contains all the user names in this page. I did not test in other pages.

user posted image

TSmumeichan
post Nov 1 2009, 03:16 PM

Member
*******
Senior Member
4,152 posts

Joined: May 2005
Thanks alot for that script. I'm learning so much now.

Please help me with another question.

The class I want to call is "username rollhover" However if I were to write
CODE

$(".username rollhover")

, jQuery will look for the the tag "rollhover" that is a child of something with the class "username" right? So how to I ask jQuery to look for classes with spaces?

This post has been edited by mumeichan: Nov 1 2009, 03:17 PM
sunsuron
post Nov 1 2009, 08:54 PM

Regular
******
Senior Member
1,334 posts

Joined: Nov 2004



Dealing with multiple class can be bit tricky but luckily jQuery provide the attr() function. We can find all the elements with specific classes with this function. Here is an example:

» Click to show Spoiler - click again to hide... «

TSmumeichan
post Nov 2 2009, 09:02 PM

Member
*******
Senior Member
4,152 posts

Joined: May 2005
QUOTE(sunsuron @ Nov 1 2009, 08:54 PM)
Dealing with multiple class can be bit tricky but luckily jQuery provide the attr() function. We can find all the elements with specific classes with this function. Here is an example:

» Click to show Spoiler - click again to hide... «

*
Thanks alot for the script. I don't quite understand it fully yet but I'm trying too. I'm still reading up a book and javascript and jQuery each. However I'm particularly mystified by this line of code below
CODE
var collection = []


What does it mean when you declare a variable and set it's value to "[]", What do empty brackets represent or do?
sunsuron
post Nov 2 2009, 09:32 PM

Regular
******
Senior Member
1,334 posts

Joined: Nov 2004



I declare a variable called collection to store array of something (in this case, usernames). It is the same effect with:

CODE
var collection = new Array();


It's just a syntax shortcut.

 

Change to:
| Lo-Fi Version
0.0194sec    0.54    5 queries    GZIP Disabled
Time is now: 6th December 2025 - 11:05 PM