Langdon
Langdon

Reputation: 20073

How to add attributes to tags in memory using Ext.js?

How would I pull this off using Ext.js?

var html = '<div><a href="a.htm">a</a><a href="b.htm">b</a></div>';

$(html).find('a').attr('target', '_blank'); // the jQuery way

Upvotes: 0

Views: 963

Answers (2)

LUKE
LUKE

Reputation: 1375

As of Ext.JS 4.1,

// createDom makes the passed 'html' a childNode 
// of a new <div id="ext-gen####"></div> element
var htmlEl = Ext.DomHelper.createDom({html: '<div><a href="a.htm">a</a><a href="b.htm">b</a></div>' }),
    memoryDom = Ext.get(htmlEl);

memoryDom.select('a').set({ target: '_blank' });

// removes the <div id="ext-gen####"></div> wrapper
console.log(memoryDom.getHTML()); 

Upvotes: 0

Evan Trimboli
Evan Trimboli

Reputation: 30082

While the first answer is correct, it does it in a really roundabout way:

var dom = Ext.DomHelper.createDom({
    html: '<a href="a.htm">a</a><a href="b.htm">b</a>'
});

Ext.get(dom).select('a').set({
    target: '_blank'
});

Upvotes: 3

Related Questions