Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Select div from string with jquery

I have string that contains some div's how to get one of them by id ?

EDIT

I'm using right click selection plugin, so when i select a div .

 $("#first #second").contextMenu({
        menu: 'myMenu'
    },
        function(action, el, pos) {
      switch (action) {
            case "do":
                {

and the selection is basicley

$(el).html()

So this is the code that contains the html that is in #second, but the #second isn't one div , it is a'lot of divs with that id, and i want when i click on that div to select certain id and get it's context . Is there a easyer way ?

like image 555
gambozygame Avatar asked Jul 22 '26 15:07

gambozygame


1 Answers

You can have jquery interpret a string as a set of tags like this:

$(htmlstring);

So something like this might work:

$("<div><div id='test'></div></div>").find("#test");

Edit: Now with the updated question this is of course not what you want.

You can't have more than one element with the same id. IDs are supposed to be unique identifiers.

like image 105
jm_toball Avatar answered Jul 24 '26 05:07

jm_toball



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!