Accesing an input element by its value
In a project repeated blocks are identified by an <input type="hidden" value="x" /> field.
To get an access to one of the block I wanted first access to that field.
My first problem is there and I will explain it by a micro-project (tested with Firefox only)
Here is the HTML code :
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
- "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
- <html>
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=utf8" />
- <meta http-equiv="Content-Style-Type" content="text/css" />
- <meta http-equiv="Content-Script-Type" content="text/javascript" />
- <link rel="stylesheet" href = "index.css" type="text/css" />
- <script type="text/javascript" src='Library/jquery-1.4.js'></script>
- <script type="text/javascript" src='index.js'></script>
- </head>
- <body>
- <div class ="pseudoFieldset" id="toutesUnions">
- <div class="pseudoFieldset">
- <input type="hidden" id="curUnion" value="1" />
- <input type="hidden" class="idUnion" value="1" />
- <p class="legend">
- <span id="nom">Cliquer</span>
- </p>
- Contenu
- </div>
- </div>
- </body>
- </html>
and here the javascript code wher is the JQuery question
- //meta http-equiv content-type charset=utf8
- function test(){
- var $id = $('#curUnion').val();
- var $objet = $('#toutesUnions > .pseudoFieldset').find('input[value=$id]');
- var $test = $objet.val();
- var $objet2 = $('#toutesUnions > .pseudoFieldset').find('input[value="1"]');
- var $test2 = $objet2.val();
- alert($test + " / " + $test2);
- var $parent = '????' //Fielset parent immediat ?????
- $html = $parent.html();
- }
- $(document).ready(function() {
- $('#nom').click ( function () {
- test();
- });
- });
With $id = "1" as shown by the Javascript debugger (in Firefox)
where is the difference between find('input[value=$id]') and find('input[value="1"]')
giving the alert result => undefined / 1
PS If you want to test the micro project you will find it in the Test.zip joined
PS2 The following question would be : How to access the immediate parent pseudoFieldset to get its html code ?