0

I want to insert a label called "octosplit-label" right under the current octosplit-label.

How do I do this in Javascript?

I had an attempt that didn't work here

function addOneCheckbox($label) {
  $('#issues-container .table-list').append($label);
}
3
  • 1
    Please post code, not images of code. How is anyone supposed to read that? What is $label? Commented Oct 29, 2014 at 23:59
  • 1
    @carlosHT: Just a note for that edit: I would have included a link to the original image when copying the code out of it, so that if something important was in the image that wasn't copied, the original is available. It's not critical but it is a good practice. Commented Oct 30, 2014 at 1:39
  • @Pokechu22 Noted, good point. Commented Nov 7, 2014 at 16:57

4 Answers 4

1

Try modifying your function like this:

function addOneCheckbox($label) {
  $('#octosplit-label').after($label);
}

Remember that IDs should be unique, so the HTML contained within $label should not have the same ID (which is octosplit-label) and also there should be no other labels currently on the page with that same ID.

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

Comments

0

This should work for you (from jQuery documents:

function addOneCheckbox($label) {
  $($label).insertAfter('#octosplit-label');
}

The $label needs to be all of the html for the label.

Comments

0

Please keep in mind that IDs have to be unique; therefore you cannot give the new label the same ID as the existing one:

$('#octosplit-label').after( $('<label/>',{'id':'some_id','for':'if_so_desired'}) );

Reference:

jQuery.after() API Documentation

Comments

0

You should add some validation before try to modifying the DOM.

function addOneCheckbox(label) {
  var element = $('#issuelist').find('#octosplit-label');

  if(element.length > 0) {
    element.append(label);
  }
}

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.