Question: I have a string that contains an HTML code snippet and I want to get the value of the `id` attribute from the element `dt`.

```
var myHtml = "<dt id='119'>Email</dt><dd id='container'>my text</dd>";

```

Expected result:

```
var myId = 119;

```

Does anyone have any ideas how I can do this?

Answer: 
You can wrap the string in jQuery and simply use `attr`

```
var myId = $(myHtml)
          .first() // get the first element - <dt>
          .attr("id"); // get the id

```

Note that you could just use `attr` since jQuery only gets the first attribute if multiple elements are involved, but using `first` is more *semantic*, or at least I think so.
You can test this in console:

```
$("<dt id='119'>Email</dt><dd id='container'>my text</dd>").eq(0).attr('id')

```