0

I have the following output.

<tr id='row_27' valign='top'>
...
...

<td width="5%"><a href="http://localhost/daikon2/index.php/projects/admin/delete_log/6/6/27" class="deleteme"><img src="http://localhost/daikon2/assets/icons/delete.png"  alt="delete"  title="Delete Log" /></a></td>
</tr>

I want to get the last segments 27 in the href with JavaScript.

I tried the following but nothing happened.

var id =href.substring(href.lastIndexOf("/") + 1);
                        alert (id);

1 Answer 1

3

Firstly, how are you getting the href variable? Here's one way:

var href = document.getElementById("row_27").getElementsByTagName("a")[0].href;

I would suggest using the slice method of the string, which takes a substring from the index to the end of the string if you specify only one parameter:

var id = href.slice(href.lastIndexOf("/") + 1);
alert(id);
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.