Javascript Question

Change innerHTML in a variable?

What's wrong with my code?

<div class="videolink">
<a onclick="var vidi = this.innerHTML;var dag = vidi.querySelector("h5").innerHTML.replace(/Bootstrap| tutorial|#/g,""); alert(dag);" class="something">
<img class="ytimg" src="https://i.ytimg.com/vi/mKt-MDwtVB4/hqdefault.jpg">
<div class="videotext">
<h5>Bootstrap tutorial #1</h5>
<p>Lorem ipsum.</p>
<p>Lorem ipsum dolor.</p>
</div>
</a>
</div>


I want to get the number
1
.

Answer

Apply the function with separate script.don't include with in a on click.

this only enough to get inner elements

this.innerHTML is not required

function somefunction (html){
var dag =html.querySelector("h5").innerHTML;
  console.log(dag.replace(/[Bootstrap|tutorial|#]/g,""))
  }
<a onclick="somefunction(this)" class="something">212
						<img class="ytimg" src="https://i.ytimg.com/vi/mKt-MDwtVB4/hqdefault.jpg">
						<div class="videotext">
							<h5>Bootstrap tutorial #1</h5>
							<p>Lorem ipsum.</p>
							<p>Lorem ipsum dolor.</p>
						</div></a>

Comments