Figure out when an empty "table cell" jQuery prefix problems

Need help with an engine or coding not on the list? Need help with a game or the website and forums here? Direct all questions here.
Post Reply
Sim
Posts: 410
Joined: Sat Dec 26, 2009 5:37 pm

Figure out when an empty "table cell" jQuery prefix problems

Post by Sim »

So after some research I figured I would try this as it would seem like the best bet:

http://api.jquery.com/attribute-contain ... -selector/

The actual page: www.orpgcreator.com/3blocks/board.php

I am trying to figure out when and which top column is clicked.

Code: Select all

<script src="//code.jquery.com/jquery-1.11.0.min.js"></script>
<script type="text/javascript">
$( "[id|='click_']" ).click(function(){
	var str = $( this ).attr( "id" );
	var the_id = str.replace("click_", ""); 
	alert(the_id);
});                        
</script>

<table height="100%" width="100%" border="1">
<?
for($x = 1; $x < 8; $x++)
{
?>
  <tr id="click_<?= $x ?>">
  <?
  for($y = 1; $y < 7; $y++)
  {
  ?>
    <td id="<?= $x . '-' . $y ?>"></td>
	<?
	}
	?>
  </tr>
<?
}
?>
</table>
oRPG Creator - Make Your Own Browser Game
oRPG Creator on Facebook
User avatar
MikuzA
Posts: 394
Joined: Thu Aug 08, 2013 8:57 am

Re: Figure out when an empty "table cell" jQuery prefix prob

Post by MikuzA »

Code: Select all

<script type="text/javascript">
$(document).ready(function() {
	$( "[id^='click_']" ).click(function(){
		   var str = $( this ).attr( "id" );
		   var the_id = str.replace("click_", ""); 
		   alert(the_id);
	});                        
});
</script>
I'm not a javascript-expert but I couldn't get it to work without the $(document).ready row :)
Why so serious?

Business Intelligence, Data Engineering, Data Mining
PHP, HTML, JavaScript, Bash/KornShell, Python, C#, PL/SQL
MySQL, DB2, Oracle, Snowflake
Pentaho, DataStage, Matillion, Unity3D, Blender
Sim
Posts: 410
Joined: Sat Dec 26, 2009 5:37 pm

Re: Figure out when an empty "table cell" jQuery prefix prob

Post by Sim »

Neat.

I wonder why

Code: Select all

$( "[id|='click_']" ).click(function(){
Has to be

Code: Select all

$( "[id^='click_']" ).click(function(){
when that link I posted says to use |=

oh well. it works now.
oRPG Creator - Make Your Own Browser Game
oRPG Creator on Facebook
User avatar
MikuzA
Posts: 394
Joined: Thu Aug 08, 2013 8:57 am

Re: Figure out when an empty "table cell" jQuery prefix prob

Post by MikuzA »

Sim wrote:Neat.

I wonder why

Code: Select all

$( "[id|='click_']" ).click(function(){
Has to be

Code: Select all

$( "[id^='click_']" ).click(function(){
when that link I posted says to use |=

oh well. it works now.
I see, I realised by studying the page that it would work if you have..
The | is waiting for an exact match or a string that is followed with a '-'.

Code: Select all

$( "[id|='click']" ).click(function(){
Then change the click_1 to click-1

Code: Select all

  <tr id="click-1">
And it works!
Why so serious?

Business Intelligence, Data Engineering, Data Mining
PHP, HTML, JavaScript, Bash/KornShell, Python, C#, PL/SQL
MySQL, DB2, Oracle, Snowflake
Pentaho, DataStage, Matillion, Unity3D, Blender
Sim
Posts: 410
Joined: Sat Dec 26, 2009 5:37 pm

Re: Figure out when an empty "table cell" jQuery prefix prob

Post by Sim »

That would explain it. =)
oRPG Creator - Make Your Own Browser Game
oRPG Creator on Facebook
Post Reply

Return to “Advanced Help and Support”