Jump to content

jQuery help

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
7 replies to this topic

#1
Guest_Jaan_*

Guest_Jaan_*
  • Guests
I have this:

And I have no idea why it don't work..

<html>

<head>

<style>


body{

	

	font-size: 11px;

	

}


.stats-box-wrapper{

	

	border: 1px #c3c3c3 solid;

	width: 300px;

	

}


.stats-box-header{

	

	border-bottom: 1px #c3c3c3 solid;

	padding: 4px;

	margin: 0px 7px;

	

}


.stats-box-date{

	

	padding: 2px;

	margin: 0px 7px;	

	

}


.stats-box-date-overall{

	

	padding: 2px;

	margin: 0px 7px;

	float: right;

	

}


.stats-box-date-today{

	

	padding: 2px;

	margin: 0px 7px;

	float: left;

		

	

}


.minimize-stats-box{

	

	float: right;


}


a{

	

	text-decoration: none;

	

}


</style>


<script type="text/javascript" src="jquery-1.3.2.min.js"></script>


<script type="text/javascript">


$(function() {

       $('.expand').click(function(){

         $(this).next('.stats-content').toggle(1500);

	});

});


</script>


<script type="text/javascript">


function exp(obj) {


	if(obj.oldText){

		obj.innerHTML = obj.oldText;

		obj.oldText = null;

	} else {

		obj.oldText = obj.innerHTML;

		obj.innerHTML = '+';

	}


}


</script>


</head>


<body>


<?php



echo "<div class='stats-box-wrapper'>";

	echo "<div class='stats-box-header'>";

	echo "<div class='minimize-stats-box'><a href='#' class='expand' onclick='javascript:exp(this);'>-</a></div>";

	echo "<font><b>Pealkiri</b></font>";

	echo "</div>";

	echo "<div class='stats-content'>";

	echo "<div class='stats-box-date-today'>";

	echo "<font><b>This month</b></font>";

	echo "</div>";

	echo "<div class='stats-box-date-overall'>";

	echo "<font><b>Overall</b></font>";

	echo "</div>";

	echo "<div style='clear:both;'></div>";

	echo "<div class='stats-box-content'>";

	

	echo "<table width='100%'><tr><td width='50%'>";

	

	echo "Proovin lampi ju";

	

	echo "</td><td width='50%'>";

	

	echo "Proov 2 lampi";

	

	echo "</td></tr></table>";

	

	echo "</div>";

	echo "</div>";	

	echo "</div>";


?>


</body>

</html>


#2
Xav

Xav

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 13,118 posts
I have never used jQuery, but why have you done this:

<?php


echo "<div class='stats-box-wrapper'>";
    echo "<div class='stats-box-header'>";
    echo "<div class='minimize-stats-box'><a href='#' class='expand' onclick='javascript:exp(this);'>-</a></div>";
    echo "<font><b>Pealkiri</b></font>";
    echo "</div>";
    echo "<div class='stats-content'>";
    echo "<div class='stats-box-date-today'>";
    echo "<font><b>This month</b></font>";
    echo "</div>";
    echo "<div class='stats-box-date-overall'>";
    echo "<font><b>Overall</b></font>";
    echo "</div>";
    echo "<div style='clear:both;'></div>";
    echo "<div class='stats-box-content'>";
    
    echo "<table width='100%'><tr><td width='50%'>";
    
    echo "Proovin lampi ju";
    
    echo "</td><td width='50%'>";
    
    echo "Proov 2 lampi";
    
    echo "</td></tr></table>";
    
    echo "</div>";
    echo "</div>";    
    echo "</div>";

?> 

What is the benefit in outputting the whole thing via PHP, as opposed to standard HTML?
Jordan said:

Good members, like yourself, stick around and post for ages to come!
Mr. Xav | Blog | Forums

#3
Guest_Jaan_*

Guest_Jaan_*
  • Guests
Because I used PHP when i copy & pasted this content thingy.. ;D that's why

#4
Xav

Xav

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 13,118 posts
lol

Do you get an error message?
Jordan said:

Good members, like yourself, stick around and post for ages to come!
Mr. Xav | Blog | Forums

#5
Guest_Jaan_*

Guest_Jaan_*
  • Guests
Nope.. Problem is that it won't toggle this

<div class='stats-content'></div>


#6
Xav

Xav

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 13,118 posts
Have you debugged it with Firebug?
Jordan said:

Good members, like yourself, stick around and post for ages to come!
Mr. Xav | Blog | Forums

#7
Guest_Jaan_*

Guest_Jaan_*
  • Guests
jQuery can't be debugged with firebug ;)
I think.. because I haven't seen any errors

#8
CameronMauch

CameronMauch

    Newbie

  • Members
  • Pip
  • 3 posts

Jaan said:

I have this:

And I have no idea why it don't work..

<html>

<head>

<style>


body{

	

	font-size: 11px;

	

}


.stats-box-wrapper{

	

	border: 1px #c3c3c3 solid;

	width: 300px;

	

}


.stats-box-header{

	

	border-bottom: 1px #c3c3c3 solid;

	padding: 4px;

	margin: 0px 7px;

	

}


.stats-box-date{

	

	padding: 2px;

	margin: 0px 7px;	

	

}


.stats-box-date-overall{

	

	padding: 2px;

	margin: 0px 7px;

	float: right;

	

}


.stats-box-date-today{

	

	padding: 2px;

	margin: 0px 7px;

	float: left;

		

	

}


.minimize-stats-box{

	

	float: right;


}


a{

	

	text-decoration: none;

	

}


</style>


<script type="text/javascript" src="jquery-1.3.2.min.js"></script>


<script type="text/javascript">


$(function() {

       $('.expand').click(function(){

         $(this).next('.stats-content').toggle(1500);

	});

});


</script>


<script type="text/javascript">


function exp(obj) {


	if(obj.oldText){

		obj.innerHTML = obj.oldText;

		obj.oldText = null;

	} else {

		obj.oldText = obj.innerHTML;

		obj.innerHTML = '+';

	}


}


</script>


</head>


<body>


<?php



echo "<div class='stats-box-wrapper'>";

	echo "<div class='stats-box-header'>";

	echo "<div class='minimize-stats-box'><a href='#' class='expand' onclick='javascript:exp(this);'>-</a></div>";

	echo "<font><b>Pealkiri</b></font>";

	echo "</div>";

	echo "<div class='stats-content'>";

	echo "<div class='stats-box-date-today'>";

	echo "<font><b>This month</b></font>";

	echo "</div>";

	echo "<div class='stats-box-date-overall'>";

	echo "<font><b>Overall</b></font>";

	echo "</div>";

	echo "<div style='clear:both;'></div>";

	echo "<div class='stats-box-content'>";

	

	echo "<table width='100%'><tr><td width='50%'>";

	

	echo "Proovin lampi ju";

	

	echo "</td><td width='50%'>";

	

	echo "Proov 2 lampi";

	

	echo "</td></tr></table>";

	

	echo "</div>";

	echo "</div>";	

	echo "</div>";


?>


</body>

</html>

The issue is actually pretty simple. The .next gives the next matching sibling, meaning at the same level. For this to work, the element with the 'stats-content' class would have to be after the anchor element inside the same div. It is in a completely different div. If I am having trouble, I usually use firebug's console.log command to display data down the jquery chain. For example, I would log $(this).next('.stats-content').html() to make sure I was getting what I expected. You would see 'undefined' because there was no match. I would replace above with just $('.stats-content'). Don't really need $(this).

Cameron