• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 249
  • Last Modified:

Compacting JQuery code

I don't know if this is possible, but I wonder if the following code can be put in one line (using sequencing) or one nested command. It works like this, but I'm just curious and want to understand JQuery better.
var title= $("#textfield").val();
$("#item td.first").html(title);

Open in new window

1 Solution
Not sure why you would want to compact it, but this is the only thing I could think of:

$("#item td.first").html($("#textfield").val());

You might however want to reduce the selector to:
$("#item td.first").html(document.getElementById('textfield').value);

R7AFAuthor Commented:
Thank you! I tried something similar, but didn't get it to work. I'm just starting with JQuery, so the "why" is more about understanding the different ways you can do things.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now