Question: I need to remove a string ("DTE\_Field\_") from the id of elements in the dom.

```
<select id="DTE_Field_CD_PAIS" dependent-group="PAIS" dependent-group-level="1" class="form-control"></select>

var str=$(el).attr("id");
str.replace("DTE_Field_","");

```

Answer: 
Use [**`attr()`** method with callback](http://api.jquery.com/attr/#attr-attributeName-function). That will iterate over element and you can get old attribute value as callback argument you can update attribute by returning string where `DTE_FIELD` using **[`String#replace`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replace)** method.

```
$('select').attr('id', function(i, oldId) {
  return oldId.replace('DTE_field_', '');
});

```

```js
$('select').attr('id', function(i, oldId) {
  return oldId.replace('DTE_Field_', '');
});
```

```html
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<select id="DTE_Field_CD_PAIS" dependent-group="PAIS" dependent-group-level="1" class="form-control"></select>
```

---

If the element is not always select then you can use **[`attribute contains selector`](https://api.jquery.com/attribute-contains-selector/)**(or if `DTE_field_` is always at the beginning then use **[`attribute starts with selector`](https://api.jquery.com/attribute-starts-with-selector/)**).

```
$('[id*="DTE_field_"]').attr('id', function(i, oldId) {
  return oldId.replace('DTE_field_', '');
});

```
```
$('[id^="DTE_FIELD_"]').each(function () {
   $(this).attr('id', $(this).attr('id').replace('DTE_FIELD_',''));
});

```