1

In the code below I need to pass the link name inorder to do some process in javascript. Now i don't know how to pass this link name in javascript. I tries passing this.value, this.innerHTML but no luck. Please can anyone help with this.

<li><a href="#tab6" onclick="hideupdatebutton(this)">Images</a></li>
0

3 Answers 3

1

Try this

function hideupdatebutton(el) {
    console.log(el.innerHTML);
}
<ul>
    <li><a href="#tab6" onclick="hideupdatebutton(this)">Images</a></li>
</ul>

Or you can pass only text, like so

function hideupdatebutton(name) {
    console.log(name);
}
<ul>
    <li><a href="#tab6" onclick="hideupdatebutton(this.innerHTML)">Images</a></li>
</ul>

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

Comments

0

You can get the name of the link by using 'text' property of anchor tag :

function hideupdatebutton(obj){
       alert(obj.text);
}

Fiddle

Comments

0
href="javascript:foo(this);"
<a href="#" onclick="foo(this)">MyLink</a>

1 Comment

Thanks for posting an answer to this question! Code-only answers are discouraged on Stack Overflow, because a code dump with no context doesn't explain how or why the solution will work, making it difficult for the original poster (or any future readers) to understand the logic behind it. Please, edit your question and include an explanation of your code so that others can benefit from your answer. –

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.