How can I get and check if the href path contain image path or some other link using jquery. For Example:
<a href="image.png"><img src="image.png"/></a>
In the above example anchor text contain the image src then only jquery function should work to find the href path.i.e., Fetch the href
path only when anchor text contain img
tag.
I reviewed the .has
in jquery api for checking the image. But how can i check if the href contain image path or some other path.
Something i am going to do based on SO User's Suggestion, like.
<script type="text/javascript">
jQuery(document).ready(function($) {
if (jQuery('a').has("img")) { // it return the no. of img tag within a
jQuery('a').has("img").prop('href', '#');
}
});
</script>
See the Above script do the action to check if anchor text contain image tag then only # on href link of anchor tag. By the same way to add like to do the above script to check if the href contain any image path or link. If the Image Path Contain on href then the above script should execute or else it won't.
Any Possible Reason For @Downvoters.?
Is it possible to do in jquery, Any Suggestion would be much appreciated.