Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
183 views
in Technique[技术] by (71.8m points)

Get number in a class name with jQuery

I would like to get the number in a class name.

I have this class only once on each page. I need to know what page I'm on when the $(window) is load.

I can't change the structure

.frm_page_num_xx

I don't get any number in my console. Is my variable correct?

I got : Uncaught TypeError: Cannot read property 'match' of undefined

var pageNum = $('[class^="frm_page_num_"]').attr('class').match(/frm_page_num_(d+)/)[1];
console.log(pageNum);
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="frm_page_num_1">
  <div class="my-content"></div>
</div>
question from:https://stackoverflow.com/questions/66064047/get-number-in-a-class-name-with-jquery

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...