As far as I can read you want to find elements HREF which matches an A element. You can do this:
jQuery("a.btn[href='" + hash + "']").trigger("click");
This will trigger a click on the a.btn
with the href=hash
.
Question
I am trying to target a generic item class with a unique href value based on if hash value is appended to the url unload I want to emulate the click that would normally happen on the page.
jQuery:
if(window.location.hash) {
var hash = window.location.hash;
function showHashVideo() {
jQuery("a.btn").attr("href", hash).trigger('click');
}
jQuery(showHashVideo);
}
HTML:
<a class="btn btn-mini" href="#help-video-modal-Graphing" data-url="video-url" data-title="Graphing">Watch Video</a>
Solution
As far as I can read you want to find elements HREF which matches an A element. You can do this:
jQuery("a.btn[href='" + hash + "']").trigger("click");
This will trigger a click on the a.btn
with the href=hash
.
OTHER TIPS
jQuery trigger will not trigger DOM event clicks, so you must do this.
jQuery("a.btn").attr("href", hash).get(0).click()
You need to use Attribute-Equals-Selector jQuery( "[attribute='value']" )
jQuery('a.btn[href="' + hash + '"]').get(0).click();