1

I am trying to find out how to pass that a variable string staffID into an id selector in the load() function. Here is the piece of code:

  $('li.staffAsset').click(function () {
    var staffID = $(this).attr("id");
    openDialog('#descrDialog');
    $('#staffDescr p').load('/staffDescr.html $("#" + staffID)');
    });

This doesn't work. Basically there are divs with id="staffID" inside the staffDescr.html. I just can't seem to find the proper syntax to pass that variable string as a proper id into the load() function. Can anyone help please?

2 Answers 2

3

You don't pass the dollar function into the string. Just use this:

$('#staffDescr p').load('/staffDescr.html #' + staffID);

See the documentation: Loading Page Fragments.


Also, there's no need for $(this).attr("id"). Just use this.id:

$('li.staffAsset').click(function () {
    openDialog('#descrDialog');
    $('#staffDescr p').load('/staffDescr.html #' + this.id);
});
Sign up to request clarification or add additional context in comments.

Comments

1

You messed the quotes. To simply put the id in your string you might replace

$('#staffDescr p').load('/staffDescr.html $("#" + staffID)');

with

$('#staffDescr p').load('/staffDescr.html $("#"' + staffID+')');

But you probably want

$('#staffDescr p').load('/staffDescr.html #' + staffID);

if you're trying to load a page fragment.

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.