1

I have a variable with HTML and CSS value . How Can I add another HTML element inside a <span > element. Like if I want to take a <a> element inside a <span> element with different class?

var newSpan = $("<span></span>", {
    title: "Double Click to Edit Groups Name",
    id:     "myInstance2",
    style:"display:none; float:left;",
    text: "Unnamed Group",
    class: "title-span"
})
3
  • 2
    Just as a semantic note, you'd technically be adding a child element to the span element. A tag specifically refers to the HTML markup that defines either the beginning or ending of a representation of that element in HTML. Commented Jun 17, 2013 at 21:42
  • Var newSpan supposed to be var newSpan Commented Jun 17, 2013 at 21:44
  • Can you Give me Example ? I am poor in javascripts . just trying to modify with little Knowledge @Joey Commented Jun 17, 2013 at 21:47

1 Answer 1

5

You can append content to that element:

newSpan.append("<a href='' class='fred'></a>");

http://api.jquery.com/append/

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.