user700515
user700515

Reputation: 59

How do I change attr() in jQuery

Here is my current format

<div class="post-item" id="4126">
  ...entry...
</div>

With this id format will return to

Error: value of attribute "id" invalid: "4" cannot start a name

Now I want to change the id will be id="post_4126"

And the question, how do I replace current jQuery will be working with the id="post_4126"

url: "more.php?lastid=" + $(".post-item:last").attr("id")

Let me know

Upvotes: 0

Views: 157

Answers (2)

Hussein
Hussein

Reputation: 42818

If i understood your question correctly, i think you want to change attr from #4126 to #post_4126 since id's cannot be pure numbers. This is how to do it:

var x = $(".post-item:last").attr("id");
url: "more.php?lastid=" + 'post_' + x;

Upvotes: 1

BrokenGlass
BrokenGlass

Reputation: 160902

url: "more.php?lastid=" + $(".post-item:last").attr("id").split('_')[1];

Upvotes: 2

Related Questions