0

Hi ,

I need to know how to pass html element into jquery function.

My sample html code is given below:

<html>
<head>
<script src='../../core/js/jquery-1.4.2.min.js'></script>
<script src='../../core/js/jquery-ui-1.8.1.min.js'></script>
<script src='../../core/js/extensions.js'></script>
<script src='../../core/js/prot-lib.js'></script>
</head>
<body>
<table>
 <tr>
  <td class='r1'>
    <chl class="chl">
            <chli class="menu-list">
              <li id="s0" class="item" onClick="handle('s0')">NJ</li>
              <li id="s1" class="item" onClick="handle('s1')">TX</li>
            </chli>
          </chl>
  </td>
  <td class='r1'>
    <chl class="chl">
            <chli class="menu-list">
              <li id="s0" class="item" onClick="handle('s0')">NJ</li>
              <li id="s1" class="item" onClick="handle('s1')">TX</li>
            </chli>
          </chl>
  </td>
 </tr>
</table>
</body>
</html>

Jquery function is given below:

function handle(id){

    var text = $('#'+id).text();    
    $('#'+id).closest('chl').find('#id').css("color","black").val(text);

}

I want to pass the html element also in handle function. Reason is the above is accessing first element always when i select second list element in html. The li id's are same for both the html elements.
Is there anyway I can pass the html element itself to the function handle() along with id?

Its immediate requirement. Any help appreciated.

Thanks in Advance,
VC

2
Contributors
4
Replies
6
Views
5 Years
Discussion Span
Last Post by pritaeas
0

Pritaeas,

Thank you for the reply. That helped. Is there a way to get random numbers to set it as id's in jquery?

thank you,
VC

0

I have another problem. After using 'this' in function, I am using it to set the value of its parent's parent to a string using val(string) function. It is neither showing any error nor working.

code:

$(this).parent().parent().find('#input-value').css("color","black").val(text);

I am able to get its value using text() function but val() is not working.
What could be the reason for this?

Thanks,
VC

0

Is there a way to get random numbers to set it as id's in jquery?

What do you want to do ? Do you mean something like this:

$('li').each(function(){
    var newId = 's' + Math.floor(Math.random() * 100);
    $(this).attr('id', newId);
});
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.