Jquery select first letter?

后端 未结 5 1198
时光说笑
时光说笑 2020-12-31 05:24

I am simply attempting to get jquery to identify the first letter of a paragraph. How would I do this?

For example, I have a page with a number of paragrahs on a pa

5条回答
  •  自闭症患者
    2020-12-31 05:52

    Try:

    jQuery('p').each(function(){     
        if(jQuery(this).text().substr(0,1).toUpperCase() == 'B'){
             jQuery(this).addClass('someclass')
        }
       })
    

    You can use PHP to clean the variable and the print it in JS:

    
    

    Or just grab it with document.location and extract it.

提交回复
热议问题