Page 1 of 1

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

Posted: Wed Oct 08, 2014 3:07 am
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>

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

Posted: Wed Oct 08, 2014 10:59 am
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 :)

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

Posted: Wed Oct 08, 2014 3:03 pm
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.

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

Posted: Thu Oct 09, 2014 5:58 am
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!

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

Posted: Thu Oct 09, 2014 6:21 am
by Sim
That would explain it. =)