2

I am using jQuery 1.4.1 and here is a simple code.

buildCol1: function() {
  var col = $('<select />', {className: 'col1' }).append($('<option />'));
  return $('<td />').append(col);
},

I am using qunit . In this case the method call is returning a jquery element. Since I am writing a test I should have something like

s = "<td><select class='col1'><option></option></select></td>"

I am not sure how do I get the fully expanded text value from a jquery element. I am sure I can get that by fully treaversing all the children. But I am hoping that there is an easier way to unit test this method.

Update:

After I posted the question I got an idea that on the returned element I can check for class name and for the right count of children. Basically this will be like inspecting the returned td to have right values.

1 Answer 1

3

So, you want to get the plain HTML source of a jQuery selection? The solution is to put it into a containing element and get that element's inner HTML:

var $myEl = $('<select />', {className: 'col1' }).append($('<option />'));
var src = $("<div></div>").append($myEl).html();
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.