user550413
user550413

Reputation: 4819

Change specific tags in a div tag using jQuery

I have a div tag:

<div id="content"><p></p><a href="#"></a></div>

I want to insert dynamically different content into the <p> tag and also into the href attribute of the <a> tag.

I am using jQuery.

Upvotes: 0

Views: 172

Answers (1)

VisioN
VisioN

Reputation: 145408

As easy as:

$("#content > p").html("Some content");
$("#content > a").prop("href", "/new/link.html");

Or in chain:

$("#content")
  .find("p").html("Some content")
    .end()
      .find("a").prop("href", "/new/link.html");

Upvotes: 4

Related Questions