Regex - Jquery to get attribute value based on end of string

Need the value of Div content, for this I am using

$('div[__jx__id="___$_912__right_panel__details_panel__vBrowser"]').text()

Giving successful result.

but the problem is, Initial string of attribute __jx__id is always changed to any dynamic number such as $_912 to $_1025...

<div class="jx_ui_html_div" __jx__id="___$_912__right_panel__details_panel__vBrowser">Chrome </div>

<div class="jx_ui_html_div" __jx__id="___$_1025__right_panel__details_panel__vBrowser">Chrome </div>

How can I use Regex expression to only match end part of string. Here right_panel__details_panel__vBrowser is always be fixed but initial is changed.

Answers 1

  • You can use filter() for this , with a regex:

    alert($('div.jx_ui_html_div').filter(
    function(){
    return ($(this).attr('__jx__id')).match(/.*right_panel__details_panel__vBrowser/);
    
    }
    
    ).text());
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
    <div class="jx_ui_html_div" __jx__id="___$_912__right_panel__details_panel__vBrowser">Chrome </div>
    
    <div class="jx_ui_html_div" __jx__id="___$_1025__right_panel__details_panel__vBrowser">Chrome </div>


Related Articles