1

I have come across a problem trying to pass some objects to a java function. I am using a jquery .each loop. My code is as follows:

$('.overme').each(function () {
    grow($(this).parent().find("#txtInput"), $(this).parent().find("#txtInputa"));
...

The grow function is as follows:

function grow (one, two) {
    var colsDefault = one.cols;
    var rowsDefault = one.rows;
         colsDefault.style.width;
...

Unfortunately I am not getting any object data. Where i'm I going wrong?

2
  • Can you show the html code - seems like you are not selecting the right item? Commented Jan 25, 2012 at 12:46
  • Functions are terminated with }, not .... Commented Jan 25, 2012 at 12:48

2 Answers 2

3

You are making several mistakes:

  • Java is not JavaScript (you are passing this to JavaScript function),
  • there are no HTML objects in this case, they are called DOM elements,
  • you are not passing DOM elements, you are passing jQuery objects (they contain DOM elements),

If you want to access DOM element within jQuery object, you have two options:

jquery_object.get(0)

or

jquery_object[0]

so your solution could look like this:

function grow (one, two) {
    var colsDefault = one.get(0).cols;
    var rowsDefault = one.get(0).rows;
         colsDefault.style.width;

EDIT:

One additional mistake: you are iterating through the elements with overme class just to find something that is referred to by ID. Because IDs are unique, you are probably making a mistake of assigning the same ID to several elements, or by making it too complex where you can just refer to them by ID (eg. instead of $(this).parent().find("#txtInput") you can use $("#txtInput")). This can be justified only by the need to do different things regarding this single element with specified ID (txtInput) is within current element's parent or not.

If you now thing you do not need to check whether #txtInput is under current element's parent, your grow() call could be shortened a lot:

grow($("#txtInput"), $("#txtInputa"));

Also give us some HTML so we can check if some errors occuring within it may be interfering.

Sign up to request clarification or add additional context in comments.

Comments

1

The Jquery Selector returns a Jquery Object and not the DOM-Element. If you want the element itself you can use

$(this).parent().find("#txtInput")[0]

1 Comment

Sorry i meant DOM-Object. The OP talked about "html objects"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.