Click here to Skip to main content
15,887,464 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
I have a dynamic div create an image click or ipad tap.
HTML
<div></div> <div>
  $("#pgNum").live("click, tap", function () {
                var v = $("#book").turn("view");
                var rel = $("#pgNum").attr("rel");
                var spl = rel.split("x");// split the number from the text
                var pgClicked = parseFloat(spl[0]);// selects the number. Here I 
                //need to loop and number selected should = becomes pgClicked. 


                $("#book").turn("page", parseInt(pgClicked));
                $("#ContentTitle").fadeOut(1000);
                $("#CView").val(v[0] + " - " + v[1]);
            });

My c# code loads the a table of contents from the databases and put them into this:
HTML
</div> <div></div> <div>
<div id="contents" class="clscontents" rel="1 Front Cover">
<ul>
<li> <a href="#" id="pgNum" rel="1 Front Cover"></a>l</i>
<li> <a href="#" id="pgNum" rel="2 IFC"></a>l</i>
<li> <a href="#" id="pgNum" rel="3 Table of Contents"></a>l</i>
<li> <a href="#" id="pgNum" rel="6 Visual Index"></a>l</i>
<li> <a href="#" id="pgNum" rel="24 Layering Light"></a>l</i>
<li> <a href="#" id="pgNum" rel="28 Clearing Crystal"></a>l</i>
</ul>
</div>

What I need is when a user chooses a page to go like 28 Clearing Crystal goto page 28 or if 6 Visual Index goto page 6.With code below and above which is the same code it only goto page 1 no matter what page I click.
JavaScript
</div> <div>
  $("#pgNum").live("click, tap", function () {
                var v = $("#book").turn("view");
                var rel = $("#pgNum").attr("rel");
                var spl = rel.split("x");
                var pgClicked = parseFloat(spl[0]);
                $("#book").turn("page", parseInt(pgClicked));
                $("#ContentTitle").fadeOut(1000);
                $("#CView").val(v[0] + " - " + v[1]);
            });

somehow I need to loop and what was
JavaScript
selected = pgClicked 

thank you in advance.
Posted
Updated 15-Oct-12 8:25am
v2
Comments
n.podbielski 15-Oct-12 17:58pm    
var spl = rel.split("x"); ?? Why?? this will always return array ["the same string",""] because in any attribute there is no "x"!

Why are you parsing first char of string (rel attribute) to Float and then to Int? How this make sense? Am I missing something?

1 solution

All of your links have the same id

id="pgNum"


So
var rel = $("#pgNum");


will always return:
<a href="#" id="pgNum" rel="1 Front Cover"></a>


and
var rel = $("#pgNum").attr("rel");


will always return:

rel="1 Front Cover"


Your strange parsing code will because of that always return 1. See my comment.
Change your click event handler code to take attribute not from element with id #pgNum, but from element that was clicked:

JavaScript
 $("#pgNum").live("click, tap", function(e){
{...}
$(e.target).attr("rel");
{...}
});
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900