views:

694

answers:

3
+4  Q: 

jQuery Selectors

Hi,

I am trying to take this from view source, i.e.:

<a  href="javascript:validateCB();"><img src="wwv_flow_file_mgr.get_file?p_security_group_id=1343380920146312332&p_flow_id=222&p_fname=submit_btn.gif" alt="Submit Details" border="0"  />

into jQuery selector format

var $templateButtons = $('img[src^="wwv_flow_file_mgr"]').parent('a');

But this doesn't seem to be correct.

Any ideas how to translate the above view source code into jQuery?

Thanks, Tony.

+1  A: 

This is very odd, it doesn't work with the selector you have, although, I think it should.

However, while not very clean, it does work using a filter as shown below.

var $templateButtons = $("img")
                       .filter(function(){
                             return $(this).attr('src')
                                    .indexOf('wwv_flow_file_mgr')==0;
                       }).parent('a');
Jose Basilio
A: 

have you tried

$('img[src^=wwv_flow_file_mgr]').parent('a')

mkoryak
Good find, attribute selectors check within the quotes for the data.
GoodEnough
Unfortunately this doesn't work either
John Rasch
+7  A: 

The problem is with the attribute selector: $('img[src^="wwv_flow_file_mgr"]')

You're experiencing a known bug in jQuery v1.3.2 - jQuery is trying to interpret the image path using its absolute URL, which means the URL it's comparing actually starts with "http://..."

You can temporarily get around this using *= (which looks for an attribute value that contains the text "wwv_flow_file_mgr" instead of starting with it):

var $templateButtons = $('img[src*="wwv_flow_file_mgr"]').parent('a');
John Rasch
Thanks for the details regarding this bug. I didn't know it existed.
Colin
Hi, tried this but I am getting the following error, i.e. "attr(...)" is null or not an object.Unsure if it's from this code snippet: $templateButtons.attr('data-submitval', function(){ return $(this).attr('onclick').toString().split('\n')[2]; }); Any help would be appreciated.
tonsils