cup_of cup_of - 5 months ago 31
jQuery Question

Remove some text from the "src" attribute using jQuery

Hello I would like to remove some text from the src attribute from an image using jQuery.

I need to use jQuery because I am using wordpress, and wordpress is automatically inserting that 150x150 into the img tag.

Here is my HTML:

<img src="http://localhost:8888/wp-content/uploads/2016/11/blog_2-150x150.jpg">

I would like to use some jQuery to remove "-150x150" from the src. So it would look like this:

<img src="http://localhost:8888/wp-content/uploads/2016/11/blog_2.jpg">

Is this possible?



Try this:

$('#img').attr('src',$('#img').attr('src').replace('-150x150', ''))

The id is '#img' in the example but you can change it for your case