javascript - TR as link, its TD as link elsewhere -


for odd reason tr's window.location.href wins against td's one. if replace them alert show in right order: td tr (,when clicked on right td.)

<tr onclick="window.location.href='order?order=3'">     <td>3</td>     <td onclick="window.location.href='user?user=bobo'">eisenreichová eva</td>     <td>08. 05. 2013</td>     <td>převodem</td>     <td>nezaplaceno</td>     <td>přijato</td>     <td>0</td>     <td></td> </tr> 

you need prevent click event bubbling <tr>. use this:

onclick="changelocation(event, 'user?user=bobo', true);" 

(you can same <tr> event too)

and declare function:

function changelocation(e, newurl, nobubble) {     if (nobubble) {         e.stoppropagation();     }     console.log("would navigating to: " + newurl);     //window.location.href = newurl; } 

(in real code, you'd remove console.log line , uncomment real part changes url)

demo: http://jsfiddle.net/yjjvy/

this allows if click on specific <td>, "win". if click anywhere else inside <tr>, "win" (since there's no other events conflicting it).


Comments

Popular posts from this blog

c# - Operator '==' incompatible with operand types 'Guid' and 'Guid' using DynamicExpression.ParseLambda<T, bool> -