1
<div class="MyName">
  majedur
</div>

I want majedur through using MyName

3

2 Answers 2

2

try this

var divText = document.getElementsByClassName('MyName')[0].innerHTML;

alert(divText);//for alert the inner text  of the div

console.log(divText);//write in console the inner text  of the div
Sign up to request clarification or add additional context in comments.

Comments

2

document.getElementsByClassName("MyName") will return you collection of element that has class "MyName", you can retrieve required by it's index

var elements= document.getElementsByClassName("MyName");

if(elements.length > 0){
     var value = elements[0].innerHTML;
}

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.